[clang] [clang] add llvm abi support (PR #121123)
https://github.com/RossComputerGuy updated https://github.com/llvm/llvm-project/pull/121123 >From 23922b886739b2e298e4288dd53d6f59e8e2e86e Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Wed, 25 Dec 2024 14:38:30 -0800 Subject: [PATCH] [clang] add llvm abi support --- clang/lib/Driver/Driver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index dc84c1b9d1cc4e..98b8e6e97419c6 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -1531,7 +1531,7 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { // Check if the environment version is valid except wasm case. llvm::Triple Triple = TC.getTriple(); - if (!Triple.isWasm()) { + if (!Triple.isWasm() && Triple.getEnvironment() != llvm::Triple::LLVM) { StringRef TripleVersionName = Triple.getEnvironmentVersionString(); StringRef TripleObjectFormat = Triple.getObjectFormatTypeName(Triple.getObjectFormat()); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [compiler-rt] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` (PR #110366)
https://github.com/zimirza updated https://github.com/llvm/llvm-project/pull/110366 From 24d7d3997bacf06a9add1ab3193d8d0adf2032ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0?= Date: Thu, 26 Dec 2024 08:29:03 +0500 Subject: [PATCH 01/37] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` Closes #107445 --- .../StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp | 4 clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc | 4 clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc | 6 ++ clang/test/Analysis/cert/env34-c.c | 9 - 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp index fefe846b6911f7..9c34d3636c8488 100644 --- a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp @@ -76,6 +76,10 @@ class InvalidPtrChecker &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, {{CDM::CLibrary, {"asctime"}, 1}, &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, + {{CDM::CLibrary, {"ctime"}, 1}, + &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, + {{CDM::CLibrary, {"localtime"}, 1}, + &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, }; // The private members of this checker corresponding to commandline options diff --git a/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc b/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc index 463ce921f0672f..aca22f869b5291 100644 --- a/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc +++ b/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc @@ -220,6 +220,10 @@ SYMBOL(and, None, ) SYMBOL(and_eq, None, ) SYMBOL(asctime, None, ) SYMBOL(asctime_s, None, ) +SYMBOL(ctime, None, ) +SYMBOL(ctime_s, None, ) +SYMBOL(localtime, None, ) +SYMBOL(localtime_s, None, ) SYMBOL(asin, None, ) SYMBOL(asinf, None, ) SYMBOL(asinh, None, ) diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc index c1927180d33976..7a08a5d3beee7a 100644 --- a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc +++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc @@ -618,6 +618,12 @@ SYMBOL(as_writable_bytes, std::, ) SYMBOL(asctime, std::, ) SYMBOL(asctime, None, ) SYMBOL(asctime, None, ) +SYMBOL(ctime, std::, ) +SYMBOL(ctime, None, ) +SYMBOL(ctime, None, ) +SYMBOL(localtime, std::, ) +SYMBOL(localtime, None, ) +SYMBOL(localtime, None, ) SYMBOL(asin, std::, ) SYMBOL(asin, None, ) SYMBOL(asin, None, ) diff --git a/clang/test/Analysis/cert/env34-c.c b/clang/test/Analysis/cert/env34-c.c index d307f0d8f4bb01..66ba0be4a67bba 100644 --- a/clang/test/Analysis/cert/env34-c.c +++ b/clang/test/Analysis/cert/env34-c.c @@ -15,7 +15,14 @@ lconv *localeconv(void); typedef struct { } tm; -char *asctime(const tm *timeptr); +char *asctime(const tm *timeptr) +; +typedef struct { +} tm; +char *ctime(const tm *timeptr); +typedef struct { +} tm; +struct tm *localtime(struct tm *tm); int strcmp(const char*, const char*); extern void foo(char *e); From 6d6f95fc0e25a4e0e0b2ee83b8c60e03fd45674e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0?= Date: Sat, 28 Sep 2024 17:20:00 +0200 Subject: [PATCH 02/37] [clang-tidy] add times to clang-tidy add `ctime` and `localtime` to unsafe functions check function --- clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp index 604a7cac0e4903..f058e5ae40680f 100644 --- a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp @@ -50,6 +50,8 @@ static StringRef getReplacementFor(StringRef FunctionName, StringRef AnnexKReplacementFunction = StringSwitch(FunctionName) .Cases("asctime", "asctime_r", "asctime_s") +.Cases("ctime", "ctime_r") +.Cases("localtime", "localtime_r") .Case("gets", "gets_s") .Default({}); if (!AnnexKReplacementFunction.empty()) From f60bbe61c02f91f287c5e8024ce03e137685ffee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0?= Date: Thu, 26 Dec 2024 08:30:17 +0500 Subject: [PATCH 03/37] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` add changes to release notes --- clang-tools-extra/docs/ReleaseNotes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index fabd0cc78ac6
[clang] [clang-tools-extra] [compiler-rt] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` (PR #110366)
https://github.com/zimirza updated https://github.com/llvm/llvm-project/pull/110366 From 24d7d3997bacf06a9add1ab3193d8d0adf2032ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0?= Date: Thu, 26 Dec 2024 08:29:03 +0500 Subject: [PATCH 01/38] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` Closes #107445 --- .../StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp | 4 clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc | 4 clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc | 6 ++ clang/test/Analysis/cert/env34-c.c | 9 - 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp index fefe846b6911f7..9c34d3636c8488 100644 --- a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp @@ -76,6 +76,10 @@ class InvalidPtrChecker &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, {{CDM::CLibrary, {"asctime"}, 1}, &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, + {{CDM::CLibrary, {"ctime"}, 1}, + &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, + {{CDM::CLibrary, {"localtime"}, 1}, + &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, }; // The private members of this checker corresponding to commandline options diff --git a/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc b/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc index 463ce921f0672f..aca22f869b5291 100644 --- a/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc +++ b/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc @@ -220,6 +220,10 @@ SYMBOL(and, None, ) SYMBOL(and_eq, None, ) SYMBOL(asctime, None, ) SYMBOL(asctime_s, None, ) +SYMBOL(ctime, None, ) +SYMBOL(ctime_s, None, ) +SYMBOL(localtime, None, ) +SYMBOL(localtime_s, None, ) SYMBOL(asin, None, ) SYMBOL(asinf, None, ) SYMBOL(asinh, None, ) diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc index c1927180d33976..7a08a5d3beee7a 100644 --- a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc +++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc @@ -618,6 +618,12 @@ SYMBOL(as_writable_bytes, std::, ) SYMBOL(asctime, std::, ) SYMBOL(asctime, None, ) SYMBOL(asctime, None, ) +SYMBOL(ctime, std::, ) +SYMBOL(ctime, None, ) +SYMBOL(ctime, None, ) +SYMBOL(localtime, std::, ) +SYMBOL(localtime, None, ) +SYMBOL(localtime, None, ) SYMBOL(asin, std::, ) SYMBOL(asin, None, ) SYMBOL(asin, None, ) diff --git a/clang/test/Analysis/cert/env34-c.c b/clang/test/Analysis/cert/env34-c.c index d307f0d8f4bb01..66ba0be4a67bba 100644 --- a/clang/test/Analysis/cert/env34-c.c +++ b/clang/test/Analysis/cert/env34-c.c @@ -15,7 +15,14 @@ lconv *localeconv(void); typedef struct { } tm; -char *asctime(const tm *timeptr); +char *asctime(const tm *timeptr) +; +typedef struct { +} tm; +char *ctime(const tm *timeptr); +typedef struct { +} tm; +struct tm *localtime(struct tm *tm); int strcmp(const char*, const char*); extern void foo(char *e); From 6d6f95fc0e25a4e0e0b2ee83b8c60e03fd45674e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0?= Date: Sat, 28 Sep 2024 17:20:00 +0200 Subject: [PATCH 02/38] [clang-tidy] add times to clang-tidy add `ctime` and `localtime` to unsafe functions check function --- clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp index 604a7cac0e4903..f058e5ae40680f 100644 --- a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp @@ -50,6 +50,8 @@ static StringRef getReplacementFor(StringRef FunctionName, StringRef AnnexKReplacementFunction = StringSwitch(FunctionName) .Cases("asctime", "asctime_r", "asctime_s") +.Cases("ctime", "ctime_r") +.Cases("localtime", "localtime_r") .Case("gets", "gets_s") .Default({}); if (!AnnexKReplacementFunction.empty()) From f60bbe61c02f91f287c5e8024ce03e137685ffee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0?= Date: Thu, 26 Dec 2024 08:30:17 +0500 Subject: [PATCH 03/38] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` add changes to release notes --- clang-tools-extra/docs/ReleaseNotes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index fabd0cc78ac6
[clang] [clang-tools-extra] [compiler-rt] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` (PR #110366)
https://github.com/zimirza updated https://github.com/llvm/llvm-project/pull/110366 From 24d7d3997bacf06a9add1ab3193d8d0adf2032ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0?= Date: Thu, 26 Dec 2024 08:29:03 +0500 Subject: [PATCH 01/39] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` Closes #107445 --- .../StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp | 4 clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc | 4 clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc | 6 ++ clang/test/Analysis/cert/env34-c.c | 9 - 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp index fefe846b6911f7..9c34d3636c8488 100644 --- a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp @@ -76,6 +76,10 @@ class InvalidPtrChecker &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, {{CDM::CLibrary, {"asctime"}, 1}, &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, + {{CDM::CLibrary, {"ctime"}, 1}, + &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, + {{CDM::CLibrary, {"localtime"}, 1}, + &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, }; // The private members of this checker corresponding to commandline options diff --git a/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc b/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc index 463ce921f0672f..aca22f869b5291 100644 --- a/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc +++ b/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc @@ -220,6 +220,10 @@ SYMBOL(and, None, ) SYMBOL(and_eq, None, ) SYMBOL(asctime, None, ) SYMBOL(asctime_s, None, ) +SYMBOL(ctime, None, ) +SYMBOL(ctime_s, None, ) +SYMBOL(localtime, None, ) +SYMBOL(localtime_s, None, ) SYMBOL(asin, None, ) SYMBOL(asinf, None, ) SYMBOL(asinh, None, ) diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc index c1927180d33976..7a08a5d3beee7a 100644 --- a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc +++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc @@ -618,6 +618,12 @@ SYMBOL(as_writable_bytes, std::, ) SYMBOL(asctime, std::, ) SYMBOL(asctime, None, ) SYMBOL(asctime, None, ) +SYMBOL(ctime, std::, ) +SYMBOL(ctime, None, ) +SYMBOL(ctime, None, ) +SYMBOL(localtime, std::, ) +SYMBOL(localtime, None, ) +SYMBOL(localtime, None, ) SYMBOL(asin, std::, ) SYMBOL(asin, None, ) SYMBOL(asin, None, ) diff --git a/clang/test/Analysis/cert/env34-c.c b/clang/test/Analysis/cert/env34-c.c index d307f0d8f4bb01..66ba0be4a67bba 100644 --- a/clang/test/Analysis/cert/env34-c.c +++ b/clang/test/Analysis/cert/env34-c.c @@ -15,7 +15,14 @@ lconv *localeconv(void); typedef struct { } tm; -char *asctime(const tm *timeptr); +char *asctime(const tm *timeptr) +; +typedef struct { +} tm; +char *ctime(const tm *timeptr); +typedef struct { +} tm; +struct tm *localtime(struct tm *tm); int strcmp(const char*, const char*); extern void foo(char *e); From 6d6f95fc0e25a4e0e0b2ee83b8c60e03fd45674e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0?= Date: Sat, 28 Sep 2024 17:20:00 +0200 Subject: [PATCH 02/39] [clang-tidy] add times to clang-tidy add `ctime` and `localtime` to unsafe functions check function --- clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp index 604a7cac0e4903..f058e5ae40680f 100644 --- a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp @@ -50,6 +50,8 @@ static StringRef getReplacementFor(StringRef FunctionName, StringRef AnnexKReplacementFunction = StringSwitch(FunctionName) .Cases("asctime", "asctime_r", "asctime_s") +.Cases("ctime", "ctime_r") +.Cases("localtime", "localtime_r") .Case("gets", "gets_s") .Default({}); if (!AnnexKReplacementFunction.empty()) From f60bbe61c02f91f287c5e8024ce03e137685ffee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0?= Date: Thu, 26 Dec 2024 08:30:17 +0500 Subject: [PATCH 03/39] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` add changes to release notes --- clang-tools-extra/docs/ReleaseNotes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index fabd0cc78ac6
[clang] [clang-tools-extra] [compiler-rt] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` (PR #110366)
https://github.com/zimirza updated https://github.com/llvm/llvm-project/pull/110366 From 24d7d3997bacf06a9add1ab3193d8d0adf2032ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0?= Date: Thu, 26 Dec 2024 08:29:03 +0500 Subject: [PATCH 01/40] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` Closes #107445 --- .../StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp | 4 clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc | 4 clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc | 6 ++ clang/test/Analysis/cert/env34-c.c | 9 - 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp index fefe846b6911f7..9c34d3636c8488 100644 --- a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp @@ -76,6 +76,10 @@ class InvalidPtrChecker &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, {{CDM::CLibrary, {"asctime"}, 1}, &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, + {{CDM::CLibrary, {"ctime"}, 1}, + &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, + {{CDM::CLibrary, {"localtime"}, 1}, + &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, }; // The private members of this checker corresponding to commandline options diff --git a/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc b/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc index 463ce921f0672f..aca22f869b5291 100644 --- a/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc +++ b/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc @@ -220,6 +220,10 @@ SYMBOL(and, None, ) SYMBOL(and_eq, None, ) SYMBOL(asctime, None, ) SYMBOL(asctime_s, None, ) +SYMBOL(ctime, None, ) +SYMBOL(ctime_s, None, ) +SYMBOL(localtime, None, ) +SYMBOL(localtime_s, None, ) SYMBOL(asin, None, ) SYMBOL(asinf, None, ) SYMBOL(asinh, None, ) diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc index c1927180d33976..7a08a5d3beee7a 100644 --- a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc +++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc @@ -618,6 +618,12 @@ SYMBOL(as_writable_bytes, std::, ) SYMBOL(asctime, std::, ) SYMBOL(asctime, None, ) SYMBOL(asctime, None, ) +SYMBOL(ctime, std::, ) +SYMBOL(ctime, None, ) +SYMBOL(ctime, None, ) +SYMBOL(localtime, std::, ) +SYMBOL(localtime, None, ) +SYMBOL(localtime, None, ) SYMBOL(asin, std::, ) SYMBOL(asin, None, ) SYMBOL(asin, None, ) diff --git a/clang/test/Analysis/cert/env34-c.c b/clang/test/Analysis/cert/env34-c.c index d307f0d8f4bb01..66ba0be4a67bba 100644 --- a/clang/test/Analysis/cert/env34-c.c +++ b/clang/test/Analysis/cert/env34-c.c @@ -15,7 +15,14 @@ lconv *localeconv(void); typedef struct { } tm; -char *asctime(const tm *timeptr); +char *asctime(const tm *timeptr) +; +typedef struct { +} tm; +char *ctime(const tm *timeptr); +typedef struct { +} tm; +struct tm *localtime(struct tm *tm); int strcmp(const char*, const char*); extern void foo(char *e); From 6d6f95fc0e25a4e0e0b2ee83b8c60e03fd45674e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0?= Date: Sat, 28 Sep 2024 17:20:00 +0200 Subject: [PATCH 02/40] [clang-tidy] add times to clang-tidy add `ctime` and `localtime` to unsafe functions check function --- clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp index 604a7cac0e4903..f058e5ae40680f 100644 --- a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp @@ -50,6 +50,8 @@ static StringRef getReplacementFor(StringRef FunctionName, StringRef AnnexKReplacementFunction = StringSwitch(FunctionName) .Cases("asctime", "asctime_r", "asctime_s") +.Cases("ctime", "ctime_r") +.Cases("localtime", "localtime_r") .Case("gets", "gets_s") .Default({}); if (!AnnexKReplacementFunction.empty()) From f60bbe61c02f91f287c5e8024ce03e137685ffee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0?= Date: Thu, 26 Dec 2024 08:30:17 +0500 Subject: [PATCH 03/40] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` add changes to release notes --- clang-tools-extra/docs/ReleaseNotes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index fabd0cc78ac6
[clang] [clang-tools-extra] [compiler-rt] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` (PR #110366)
https://github.com/zimirza updated https://github.com/llvm/llvm-project/pull/110366 From 24d7d3997bacf06a9add1ab3193d8d0adf2032ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0?= Date: Thu, 26 Dec 2024 08:29:03 +0500 Subject: [PATCH 01/36] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` Closes #107445 --- .../StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp | 4 clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc | 4 clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc | 6 ++ clang/test/Analysis/cert/env34-c.c | 9 - 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp index fefe846b6911f7..9c34d3636c8488 100644 --- a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp @@ -76,6 +76,10 @@ class InvalidPtrChecker &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, {{CDM::CLibrary, {"asctime"}, 1}, &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, + {{CDM::CLibrary, {"ctime"}, 1}, + &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, + {{CDM::CLibrary, {"localtime"}, 1}, + &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, }; // The private members of this checker corresponding to commandline options diff --git a/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc b/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc index 463ce921f0672f..aca22f869b5291 100644 --- a/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc +++ b/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc @@ -220,6 +220,10 @@ SYMBOL(and, None, ) SYMBOL(and_eq, None, ) SYMBOL(asctime, None, ) SYMBOL(asctime_s, None, ) +SYMBOL(ctime, None, ) +SYMBOL(ctime_s, None, ) +SYMBOL(localtime, None, ) +SYMBOL(localtime_s, None, ) SYMBOL(asin, None, ) SYMBOL(asinf, None, ) SYMBOL(asinh, None, ) diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc index c1927180d33976..7a08a5d3beee7a 100644 --- a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc +++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc @@ -618,6 +618,12 @@ SYMBOL(as_writable_bytes, std::, ) SYMBOL(asctime, std::, ) SYMBOL(asctime, None, ) SYMBOL(asctime, None, ) +SYMBOL(ctime, std::, ) +SYMBOL(ctime, None, ) +SYMBOL(ctime, None, ) +SYMBOL(localtime, std::, ) +SYMBOL(localtime, None, ) +SYMBOL(localtime, None, ) SYMBOL(asin, std::, ) SYMBOL(asin, None, ) SYMBOL(asin, None, ) diff --git a/clang/test/Analysis/cert/env34-c.c b/clang/test/Analysis/cert/env34-c.c index d307f0d8f4bb01..66ba0be4a67bba 100644 --- a/clang/test/Analysis/cert/env34-c.c +++ b/clang/test/Analysis/cert/env34-c.c @@ -15,7 +15,14 @@ lconv *localeconv(void); typedef struct { } tm; -char *asctime(const tm *timeptr); +char *asctime(const tm *timeptr) +; +typedef struct { +} tm; +char *ctime(const tm *timeptr); +typedef struct { +} tm; +struct tm *localtime(struct tm *tm); int strcmp(const char*, const char*); extern void foo(char *e); From 6d6f95fc0e25a4e0e0b2ee83b8c60e03fd45674e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0?= Date: Sat, 28 Sep 2024 17:20:00 +0200 Subject: [PATCH 02/36] [clang-tidy] add times to clang-tidy add `ctime` and `localtime` to unsafe functions check function --- clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp index 604a7cac0e4903..f058e5ae40680f 100644 --- a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp @@ -50,6 +50,8 @@ static StringRef getReplacementFor(StringRef FunctionName, StringRef AnnexKReplacementFunction = StringSwitch(FunctionName) .Cases("asctime", "asctime_r", "asctime_s") +.Cases("ctime", "ctime_r") +.Cases("localtime", "localtime_r") .Case("gets", "gets_s") .Default({}); if (!AnnexKReplacementFunction.empty()) From f60bbe61c02f91f287c5e8024ce03e137685ffee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0?= Date: Thu, 26 Dec 2024 08:30:17 +0500 Subject: [PATCH 03/36] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` add changes to release notes --- clang-tools-extra/docs/ReleaseNotes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index fabd0cc78ac6
[clang] [llvm] Clang/buildFMulAdd: Use negated attribute (PR #121038)
https://github.com/arsenm edited https://github.com/llvm/llvm-project/pull/121038 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Clang/buildFMulAdd: Use negated attribute (PR #121038)
@@ -4120,6 +4120,10 @@ static Value* buildFMulAdd(llvm::Instruction *MulOp, Value *Addend, CGF.CGM.getIntrinsic(llvm::Intrinsic::experimental_constrained_fmuladd, Addend->getType()), {MulOp0, MulOp1, Addend}); +if (negMul) + dyn_cast(FMulAdd)->addParamAttr(0, llvm::Attribute::Negated); arsenm wrote: unchecked dyn_cast https://github.com/llvm/llvm-project/pull/121038 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Clang/buildFMulAdd: Use negated attribute (PR #121038)
https://github.com/arsenm requested changes to this pull request. Can't really use an attribute for this. Attributes should not be used for adding constraints to an operation https://github.com/llvm/llvm-project/pull/121038 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 676b48d - [C++20] [Modules] Diagnose if import statement lakcs a semicolon
Author: Chuanqi Xu Date: 2024-12-25T17:45:28+08:00 New Revision: 676b48d1ccd8223bb0bd889cce13e6faecd20c6d URL: https://github.com/llvm/llvm-project/commit/676b48d1ccd8223bb0bd889cce13e6faecd20c6d DIFF: https://github.com/llvm/llvm-project/commit/676b48d1ccd8223bb0bd889cce13e6faecd20c6d.diff LOG: [C++20] [Modules] Diagnose if import statement lakcs a semicolon Close https://github.com/llvm/llvm-project/issues/121066 Now we will diagnose that the import statement lacks a semicolon as expected. Note that the original "not found" diagnose message remains. I meant to remove that, but the test shows it might be more complex process (other unexpected diagnose shows up). Given the importance of the issue, I chose to not dig deeper. Added: clang/test/Modules/pr121066.cpp Modified: clang/lib/Parse/Parser.cpp clang/test/CXX/basic/basic.link/p3.cpp Removed: diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index 8ba6a5dce8a994..0710542f5e938e 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -2654,10 +2654,10 @@ Decl *Parser::ParseModuleImport(SourceLocation AtLoc, SeenError = false; break; } - if (SeenError) { -ExpectAndConsumeSemi(diag::err_module_expected_semi); + ExpectAndConsumeSemi(diag::err_module_expected_semi); + + if (SeenError) return nullptr; - } DeclResult Import; if (HeaderUnit) @@ -2666,7 +2666,6 @@ Decl *Parser::ParseModuleImport(SourceLocation AtLoc, else if (!Path.empty()) Import = Actions.ActOnModuleImport(StartLoc, ExportLoc, ImportLoc, Path, IsPartition); - ExpectAndConsumeSemi(diag::err_module_expected_semi); if (Import.isInvalid()) return nullptr; diff --git a/clang/test/CXX/basic/basic.link/p3.cpp b/clang/test/CXX/basic/basic.link/p3.cpp index 23f39d11b655a6..01202264d2591b 100644 --- a/clang/test/CXX/basic/basic.link/p3.cpp +++ b/clang/test/CXX/basic/basic.link/p3.cpp @@ -15,7 +15,8 @@ export module m; // #1 // Import errors are fatal, so we test them in isolation. #if IMPORT_ERROR == 1 -import x = {}; // expected-error {{module 'x' not found}} +import x = {}; // expected-error {{expected ';' after module name}} + // expected-error@-1 {{module 'x' not found}} #elif IMPORT_ERROR == 2 struct X; diff --git a/clang/test/Modules/pr121066.cpp b/clang/test/Modules/pr121066.cpp new file mode 100644 index 00..e92a81c53d683f --- /dev/null +++ b/clang/test/Modules/pr121066.cpp @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 -std=c++20 -fsyntax-only %s -verify + +import mod // expected-error {{expected ';' after module name}} + // expected-error@-1 {{module 'mod' not found}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][dataflow] Add matchers for smart pointer accessors to be cached (PR #120102)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-ppc64-aix` running on `aix-ppc64` while building `clang` at step 3 "clean-build-dir". Full details are available at: https://lab.llvm.org/buildbot/#/builders/64/builds/1777 Here is the relevant piece of the build log for the reference ``` Step 3 (clean-build-dir) failure: Delete failed. (failure) (timed out) Step 5 (build-unified-tree) failure: build (failure) ... 4799.980 [1109/10/4111] Building CXX object tools/clang/lib/Analysis/plugins/CheckerOptionHandling/CMakeFiles/CheckerOptionHandlingAnalyzerPlugin.dir/CheckerOptionHandling.cpp.o 4806.130 [1108/10/4112] Building CXX object tools/clang/lib/Analysis/FlowSensitive/CMakeFiles/obj.clangAnalysisFlowSensitive.dir/SimplifyConstraints.cpp.o 4807.202 [1107/10/4113] Building CXX object tools/clang/lib/Analysis/FlowSensitive/CMakeFiles/obj.clangAnalysisFlowSensitive.dir/ASTOps.cpp.o 4808.591 [1106/10/4114] Building CXX object tools/clang/lib/Analysis/FlowSensitive/CMakeFiles/obj.clangAnalysisFlowSensitive.dir/Logger.cpp.o 4808.932 [1105/10/4115] Building CXX object tools/clang/lib/Analysis/FlowSensitive/CMakeFiles/obj.clangAnalysisFlowSensitive.dir/HTMLLogger.cpp.o 4809.148 [1104/10/4116] Building CXX object tools/clang/lib/Analysis/FlowSensitive/CMakeFiles/obj.clangAnalysisFlowSensitive.dir/RecordOps.cpp.o 4813.064 [1103/10/4117] Building CXX object tools/clang/lib/Analysis/FlowSensitive/CMakeFiles/obj.clangAnalysisFlowSensitive.dir/WatchedLiteralsSolver.cpp.o 4813.208 [1102/10/4118] Building CXX object tools/clang/lib/Analysis/FlowSensitive/CMakeFiles/obj.clangAnalysisFlowSensitive.dir/Value.cpp.o 4813.435 [1101/10/4119] Building CXX object tools/clang/lib/Analysis/FlowSensitive/CMakeFiles/obj.clangAnalysisFlowSensitive.dir/DataflowAnalysisContext.cpp.o 4814.830 [1100/10/4120] Building CXX object tools/clang/lib/Analysis/FlowSensitive/CMakeFiles/obj.clangAnalysisFlowSensitive.dir/SmartPointerAccessorCaching.cpp.o FAILED: tools/clang/lib/Analysis/FlowSensitive/CMakeFiles/obj.clangAnalysisFlowSensitive.dir/SmartPointerAccessorCaching.cpp.o /usr/local/clang-17.0.2/bin/clang++ -DCLANG_EXPORTS -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_LARGE_FILE_API -D_XOPEN_SOURCE=700 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/tools/clang/lib/Analysis/FlowSensitive -I/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/clang/lib/Analysis/FlowSensitive -I/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/clang/include -I/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/tools/clang/include -I/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/include -I/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/llvm/include -mcmodel=large -fPIC -Werror -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -Wno-nested-anon-types -O3 -DNDEBUG -std=c++17 -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT tools/clang/lib/Analysis/FlowSensitive/CMakeFiles/obj.clangAnalysisFlowSensitive.dir/SmartPointerAccessorCaching.cpp.o -MF tools/clang/lib/Analysis/FlowSensitive/CMakeFiles/obj.clangAnalysisFlowSensitive.dir/SmartPointerAccessorCaching.cpp.o.d -o tools/clang/lib/Analysis/FlowSensitive/CMakeFiles/obj.clangAnalysisFlowSensitive.dir/SmartPointerAccessorCaching.cpp.o -c /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/clang/lib/Analysis/FlowSensitive/SmartPointerAccessorCaching.cpp /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/clang/lib/Analysis/FlowSensitive/SmartPointerAccessorCaching.cpp:75:5: error: unannotated fall-through between switch labels [-Werror,-Wimplicit-fallthrough] 75 | default: | ^ /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/clang/lib/Analysis/FlowSensitive/SmartPointerAccessorCaching.cpp:75:5: note: insert 'break;' to avoid fall-through 75 | default: | ^ | break; 1 error generated. 4815.495 [1100/9/4121] Building CXX object tools/clang/lib/Analysis/FlowSensitive/CMakeFiles/obj.clangAnalysisFlowSensitive.dir/DebugSupport.cpp.o 4818.237 [1100/8/4122] Building CXX object tools/clang/lib/Analysis/FlowSensitive/CMakeFiles/obj.clangAnalysisFlowSensitive.dir/DataflowEnvironment.cpp.o 4820.273 [1100/7/4123] Building CXX object tools/clang/lib/Edit/CMakeFiles/obj.clangEdit.dir/Commit.cpp.o 4821.196 [1100/6/4124] Building CXX object tools/cla
[clang-tools-extra] [clang-tidy][clangd] Fixed removeFunctionArgs don't remove comma for use-ranges check (PR #118568)
https://github.com/chomosuke edited https://github.com/llvm/llvm-project/pull/118568 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][clangd] Fixed removeFunctionArgs don't remove comma for use-ranges check (PR #118568)
https://github.com/chomosuke edited https://github.com/llvm/llvm-project/pull/118568 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][clangd] Fixed removeFunctionArgs don't remove comma for use-ranges check (PR #118568)
@@ -173,21 +174,21 @@ static void removeFunctionArgs(DiagnosticBuilder &Diag, const CallExpr &Call, for (unsigned Index : Sorted) { const Expr *Arg = Call.getArg(Index); if (Commas[Index]) { - if (Index >= Commas.size()) { -Diag << FixItHint::CreateRemoval(Arg->getSourceRange()); - } else { + if (Index + 1 < Call.getNumArgs()) { // Remove the next comma Commas[Index + 1] = true; +const Expr *NextArg = Call.getArg(Index + 1); Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange( -{Arg->getBeginLoc(), - Lexer::getLocForEndOfToken( - Arg->getEndLoc(), 0, Ctx.getSourceManager(), Ctx.getLangOpts()) - .getLocWithOffset(1)})); +{Arg->getBeginLoc(), NextArg->getBeginLoc().getLocWithOffset(-1)})); chomosuke wrote: My newest commit finds the exact location of `,` and removes it, so ```diff void f(int a, int b); void g() { - f(/*a*/0, /*b*/1); + f(/*a*/0 /*b*/); } ``` I think this is better than assuming the inline comment are parameter documentation. My code would fail though, in the case of a comment between the argument and the comma containing a comma in itself, something like ```diff void f(int a, int b); void g() { - f(/*a*/0 /*bla, bla*/, /*b*/1); + f(/*a*/0 /*bla bla*/, /*b*/); } ``` In this case the comma in the comment gets removed instead of the comma after the comment. I would appreciate if someone can point me to how to avoid that but I also think it's not a big deal since I don't people put their inline comment after an argument but before the comma like that very often. https://github.com/llvm/llvm-project/pull/118568 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][clangd] Fixed removeFunctionArgs don't remove comma for use-ranges check (PR #118568)
https://github.com/chomosuke edited https://github.com/llvm/llvm-project/pull/118568 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][clangd] Fixed removeFunctionArgs don't remove comma for use-ranges check (PR #118568)
https://github.com/chomosuke edited https://github.com/llvm/llvm-project/pull/118568 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 2d6e7c2 - [Clang][Xtensa] Add Xtensa target. (#118008)
Author: Alexey Gerenkov Date: 2024-12-25T09:56:15+01:00 New Revision: 2d6e7c2b359d4cafca8eaca4c9ed308a3a8fa6c1 URL: https://github.com/llvm/llvm-project/commit/2d6e7c2b359d4cafca8eaca4c9ed308a3a8fa6c1 DIFF: https://github.com/llvm/llvm-project/commit/2d6e7c2b359d4cafca8eaca4c9ed308a3a8fa6c1.diff LOG: [Clang][Xtensa] Add Xtensa target. (#118008) This PR implements support for generic Xtensa target in CLang. Co-authored-by: Andrei Safronov Added: clang/lib/Basic/Targets/Xtensa.cpp clang/lib/Basic/Targets/Xtensa.h Modified: clang/include/clang/Basic/TargetInfo.h clang/lib/AST/ASTContext.cpp clang/lib/Basic/CMakeLists.txt clang/lib/Basic/Targets.cpp clang/lib/Driver/ToolChains/CommonArgs.cpp clang/test/Preprocessor/init.c clang/test/Preprocessor/stdint.c Removed: diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index 82bd537b242c1c..f2905f30a7c34b 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -358,7 +358,14 @@ class TargetInfo : public TransferrableTargetInfo, //void *__saved_reg_area_end_pointer; //void *__overflow_area_pointer; //} va_list; -HexagonBuiltinVaList +HexagonBuiltinVaList, + +// typedef struct __va_list_tag { +//int* __va_stk; +//int* __va_reg; +//int __va_ndx; +//} va_list; +XtensaABIBuiltinVaList }; protected: diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 6ec927e13a7552..8b4ae58e8427a9 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -9751,6 +9751,43 @@ static TypedefDecl *CreateHexagonBuiltinVaListDecl(const ASTContext *Context) { return Context->buildImplicitTypedef(VaListTagArrayType, "__builtin_va_list"); } +static TypedefDecl * +CreateXtensaABIBuiltinVaListDecl(const ASTContext *Context) { + // typedef struct __va_list_tag { + RecordDecl *VaListTagDecl = Context->buildImplicitRecord("__va_list_tag"); + + VaListTagDecl->startDefinition(); + + // int* __va_stk; + // int* __va_reg; + // int __va_ndx; + constexpr size_t NumFields = 3; + QualType FieldTypes[NumFields] = {Context->getPointerType(Context->IntTy), +Context->getPointerType(Context->IntTy), +Context->IntTy}; + const char *FieldNames[NumFields] = {"__va_stk", "__va_reg", "__va_ndx"}; + + // Create fields + for (unsigned i = 0; i < NumFields; ++i) { +FieldDecl *Field = FieldDecl::Create( +*Context, VaListTagDecl, SourceLocation(), SourceLocation(), +&Context->Idents.get(FieldNames[i]), FieldTypes[i], /*TInfo=*/nullptr, +/*BitWidth=*/nullptr, +/*Mutable=*/false, ICIS_NoInit); +Field->setAccess(AS_public); +VaListTagDecl->addDecl(Field); + } + VaListTagDecl->completeDefinition(); + Context->VaListTagDecl = VaListTagDecl; + QualType VaListTagType = Context->getRecordType(VaListTagDecl); + + // } __va_list_tag; + TypedefDecl *VaListTagTypedefDecl = + Context->buildImplicitTypedef(VaListTagType, "__builtin_va_list"); + + return VaListTagTypedefDecl; +} + static TypedefDecl *CreateVaListDecl(const ASTContext *Context, TargetInfo::BuiltinVaListKind Kind) { switch (Kind) { @@ -9772,6 +9809,8 @@ static TypedefDecl *CreateVaListDecl(const ASTContext *Context, return CreateSystemZBuiltinVaListDecl(Context); case TargetInfo::HexagonBuiltinVaList: return CreateHexagonBuiltinVaListDecl(Context); + case TargetInfo::XtensaABIBuiltinVaList: +return CreateXtensaABIBuiltinVaListDecl(Context); } llvm_unreachable("Unhandled __builtin_va_list type kind"); diff --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt index e11e1ac4a6fa63..331dfbb3f4b67e 100644 --- a/clang/lib/Basic/CMakeLists.txt +++ b/clang/lib/Basic/CMakeLists.txt @@ -120,6 +120,7 @@ add_clang_library(clangBasic Targets/WebAssembly.cpp Targets/X86.cpp Targets/XCore.cpp + Targets/Xtensa.cpp TokenKinds.cpp TypeTraits.cpp Version.cpp diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index d0815ad33bc759..be5dedbe8044e2 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -40,6 +40,7 @@ #include "Targets/WebAssembly.h" #include "Targets/X86.h" #include "Targets/XCore.h" +#include "Targets/Xtensa.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/DiagnosticFrontend.h" #include "llvm/ADT/StringExtras.h" @@ -751,6 +752,9 @@ std::unique_ptr AllocateTarget(const llvm::Triple &Triple, default: return std::make_unique(Triple, Opts); } + + case llvm::Triple::xtensa: +return std::make_unique(Triple, Opts); } } } // namespace targets diff --git a/clang/lib/Basic/Targets/Xtensa.cpp b/clang/l
[clang] [Clang][Xtensa] Add Xtensa target. (PR #118008)
github-actions[bot] wrote: @gerekon Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail [here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr). If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of [LLVM development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy). You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! https://github.com/llvm/llvm-project/pull/118008 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Xtensa] Add Xtensa target. (PR #118008)
https://github.com/sstefan1 closed https://github.com/llvm/llvm-project/pull/118008 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][clangd] Fixed removeFunctionArgs don't remove comma for use-ranges check (PR #118568)
https://github.com/chomosuke updated https://github.com/llvm/llvm-project/pull/118568 >From b43a2602025bdacea06ced5171904fb5d765de9f Mon Sep 17 00:00:00 2001 From: chomosuke Date: Tue, 3 Dec 2024 07:10:33 + Subject: [PATCH] fixed removeFunctionArgs don't remove comma --- .../clang-tidy/utils/UseRangesCheck.cpp | 19 ++- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp index aba4d17ccd035e..88cba70b931d5d 100644 --- a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp +++ b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp @@ -28,6 +28,7 @@ #include "llvm/ADT/Twine.h" #include "llvm/Support/raw_ostream.h" #include +#include #include #include @@ -173,21 +174,21 @@ static void removeFunctionArgs(DiagnosticBuilder &Diag, const CallExpr &Call, for (unsigned Index : Sorted) { const Expr *Arg = Call.getArg(Index); if (Commas[Index]) { - if (Index >= Commas.size()) { -Diag << FixItHint::CreateRemoval(Arg->getSourceRange()); - } else { + if (Index + 1 < Call.getNumArgs()) { // Remove the next comma Commas[Index + 1] = true; +const Expr *NextArg = Call.getArg(Index + 1); Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange( -{Arg->getBeginLoc(), - Lexer::getLocForEndOfToken( - Arg->getEndLoc(), 0, Ctx.getSourceManager(), Ctx.getLangOpts()) - .getLocWithOffset(1)})); +{Arg->getBeginLoc(), NextArg->getBeginLoc().getLocWithOffset(-1)})); + } else { +Diag << FixItHint::CreateRemoval(Arg->getSourceRange()); } } else { - Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange( - Arg->getBeginLoc().getLocWithOffset(-1), Arg->getEndLoc())); + // At this point we know Index > 0 because `Commas[0] = true` earlier Commas[Index] = true; + const Expr *PrevArg = Call.getArg(Index - 1); + Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange( + PrevArg->getEndLoc().getLocWithOffset(1), Arg->getEndLoc())); } } } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][clangd] Fixed removeFunctionArgs don't remove comma for use-ranges check (PR #118568)
https://github.com/chomosuke updated https://github.com/llvm/llvm-project/pull/118568 >From b43a2602025bdacea06ced5171904fb5d765de9f Mon Sep 17 00:00:00 2001 From: chomosuke Date: Tue, 3 Dec 2024 07:10:33 + Subject: [PATCH 1/2] fixed removeFunctionArgs don't remove comma --- .../clang-tidy/utils/UseRangesCheck.cpp | 19 ++- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp index aba4d17ccd035e..88cba70b931d5d 100644 --- a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp +++ b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp @@ -28,6 +28,7 @@ #include "llvm/ADT/Twine.h" #include "llvm/Support/raw_ostream.h" #include +#include #include #include @@ -173,21 +174,21 @@ static void removeFunctionArgs(DiagnosticBuilder &Diag, const CallExpr &Call, for (unsigned Index : Sorted) { const Expr *Arg = Call.getArg(Index); if (Commas[Index]) { - if (Index >= Commas.size()) { -Diag << FixItHint::CreateRemoval(Arg->getSourceRange()); - } else { + if (Index + 1 < Call.getNumArgs()) { // Remove the next comma Commas[Index + 1] = true; +const Expr *NextArg = Call.getArg(Index + 1); Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange( -{Arg->getBeginLoc(), - Lexer::getLocForEndOfToken( - Arg->getEndLoc(), 0, Ctx.getSourceManager(), Ctx.getLangOpts()) - .getLocWithOffset(1)})); +{Arg->getBeginLoc(), NextArg->getBeginLoc().getLocWithOffset(-1)})); + } else { +Diag << FixItHint::CreateRemoval(Arg->getSourceRange()); } } else { - Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange( - Arg->getBeginLoc().getLocWithOffset(-1), Arg->getEndLoc())); + // At this point we know Index > 0 because `Commas[0] = true` earlier Commas[Index] = true; + const Expr *PrevArg = Call.getArg(Index - 1); + Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange( + PrevArg->getEndLoc().getLocWithOffset(1), Arg->getEndLoc())); } } } >From 644c8491e0fba203e89595827781d0c2c0609081 Mon Sep 17 00:00:00 2001 From: chomosuke Date: Mon, 23 Dec 2024 05:17:08 +1100 Subject: [PATCH 2/2] find , and remove only , --- .../clang-tidy/utils/UseRangesCheck.cpp | 49 +++ 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp index 88cba70b931d5d..8b8e44a9898fdd 100644 --- a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp +++ b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp @@ -28,7 +28,6 @@ #include "llvm/ADT/Twine.h" #include "llvm/Support/raw_ostream.h" #include -#include #include #include @@ -165,6 +164,33 @@ void UseRangesCheck::registerMatchers(MatchFinder *Finder) { static void removeFunctionArgs(DiagnosticBuilder &Diag, const CallExpr &Call, ArrayRef Indexes, const ASTContext &Ctx) { + auto GetCommaLoc = + [&](SourceLocation BeginLoc, + SourceLocation EndLoc) -> std::optional { +auto Invalid = false; +auto SourceText = Lexer::getSourceText( +CharSourceRange::getCharRange({BeginLoc, EndLoc}), +Ctx.getSourceManager(), Ctx.getLangOpts(), &Invalid); +assert(!Invalid); + +size_t I = 0; +while (I < SourceText.size() && SourceText[I] != ',') { + I++; +} + +if (I < SourceText.size()) { + // also remove space after , + size_t J = I + 1; + while (J < SourceText.size() && SourceText[J] == ' ') { +J++; + } + + return std::make_optional(CharSourceRange::getCharRange( + {BeginLoc.getLocWithOffset(I), BeginLoc.getLocWithOffset(J)})); +} +return std::nullopt; + }; + llvm::SmallVector Sorted(Indexes); llvm::sort(Sorted); // Keep track of commas removed @@ -176,20 +202,25 @@ static void removeFunctionArgs(DiagnosticBuilder &Diag, const CallExpr &Call, if (Commas[Index]) { if (Index + 1 < Call.getNumArgs()) { // Remove the next comma -Commas[Index + 1] = true; const Expr *NextArg = Call.getArg(Index + 1); -Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange( -{Arg->getBeginLoc(), NextArg->getBeginLoc().getLocWithOffset(-1)})); - } else { -Diag << FixItHint::CreateRemoval(Arg->getSourceRange()); +auto CommaLoc = GetCommaLoc(Arg->getEndLoc().getLocWithOffset(1), +NextArg->getBeginLoc()); +if (CommaLoc) { + Commas[Index + 1] = true; + Diag << FixItHint::CreateRemoval(*CommaLoc); +} } } else { // At this point we know Index > 0 becau
[clang] [Clang] Added nullptr check to getFriendDecl access (PR #121056)
cor3ntin wrote: Can you add a test? (and a release note) Thanks! https://github.com/llvm/llvm-project/pull/121056 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SYCL] do not support any SYCL standard except 2020 (PR #120258)
https://github.com/abhilash1910 approved this pull request. https://github.com/llvm/llvm-project/pull/120258 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] clang-format-ignore: Add support for double asterisk patterns (PR #110560)
GloryOfNight wrote: I want to express support for this feature. Just today I attempted to integrate .clang-format-ignore and was really confused by fact that it cannot ignore recursively. Project I wanted to integrate it to has a lot of generated files which is all over the place. It's very inconvenient have to use that pattern for every directory I want to ignore: ``` imported/* imported/*/* imported/*/*/* ``` `DisableFormat ` is also inconvenient, since placing .clang-format with disabled formatting all over the project not exactly a solution I would want to go with either. Just having single .clang-format-ignore file with `imported/**` would be much more convenient way to do things. IMO. https://github.com/llvm/llvm-project/pull/110560 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][clangd] Fixed removeFunctionArgs don't remove comma for use-ranges check (PR #118568)
@@ -173,22 +200,27 @@ static void removeFunctionArgs(DiagnosticBuilder &Diag, const CallExpr &Call, for (unsigned Index : Sorted) { const Expr *Arg = Call.getArg(Index); if (Commas[Index]) { - if (Index >= Commas.size()) { -Diag << FixItHint::CreateRemoval(Arg->getSourceRange()); - } else { + if (Index + 1 < Call.getNumArgs()) { // Remove the next comma -Commas[Index + 1] = true; -Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange( -{Arg->getBeginLoc(), - Lexer::getLocForEndOfToken( - Arg->getEndLoc(), 0, Ctx.getSourceManager(), Ctx.getLangOpts()) - .getLocWithOffset(1)})); +const Expr *NextArg = Call.getArg(Index + 1); +auto CommaLoc = GetCommaLoc(Arg->getEndLoc().getLocWithOffset(1), +NextArg->getBeginLoc()); +if (CommaLoc) { + Commas[Index + 1] = true; + Diag << FixItHint::CreateRemoval(*CommaLoc); +} } } else { - Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange( - Arg->getBeginLoc().getLocWithOffset(-1), Arg->getEndLoc())); - Commas[Index] = true; + // At this point we know Index > 0 because `Commas[0] = true` earlier + const Expr *PrevArg = Call.getArg(Index - 1); + auto CommaLoc = GetCommaLoc(PrevArg->getEndLoc().getLocWithOffset(1), EugeneZelenko wrote: Ditto. https://github.com/llvm/llvm-project/pull/118568 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][clangd] Fixed removeFunctionArgs don't remove comma for use-ranges check (PR #118568)
@@ -173,22 +200,27 @@ static void removeFunctionArgs(DiagnosticBuilder &Diag, const CallExpr &Call, for (unsigned Index : Sorted) { const Expr *Arg = Call.getArg(Index); if (Commas[Index]) { - if (Index >= Commas.size()) { -Diag << FixItHint::CreateRemoval(Arg->getSourceRange()); - } else { + if (Index + 1 < Call.getNumArgs()) { // Remove the next comma -Commas[Index + 1] = true; -Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange( -{Arg->getBeginLoc(), - Lexer::getLocForEndOfToken( - Arg->getEndLoc(), 0, Ctx.getSourceManager(), Ctx.getLangOpts()) - .getLocWithOffset(1)})); +const Expr *NextArg = Call.getArg(Index + 1); +auto CommaLoc = GetCommaLoc(Arg->getEndLoc().getLocWithOffset(1), EugeneZelenko wrote: Please do not use `auto` if type is not explicitly spelled in same statement or iterator. https://github.com/llvm/llvm-project/pull/118568 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][clangd] Fixed removeFunctionArgs don't remove comma for use-ranges check (PR #118568)
https://github.com/EugeneZelenko edited https://github.com/llvm/llvm-project/pull/118568 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][clangd] Fixed removeFunctionArgs don't remove comma for use-ranges check (PR #118568)
https://github.com/EugeneZelenko commented: Please mention changes in Release Notes. https://github.com/llvm/llvm-project/pull/118568 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Reapply "[Driver][OHOS] Fix lld link issue for OHOS (#118192)" (PR #120159)
phuang wrote: > We need a test to clang/test/Driver/ohos.c similar to linux-ld.c > clang_rt.crtbegin.o. > > You can add UNSUPPORTED: system-windows to ohos.c so that we don't need > backslashes. [ohos.c](https://github.com/llvm/llvm-project/blob/main/clang/test/Driver/ohos.c#L25 ) already has many tests for it. This PR changes behavior of function [OHOS::getCompilerRT()](https://github.com/llvm/llvm-project/pull/120159/files#diff-763eb55ff16745f240d46c78f988f7a2010f61d2ae2550260b3dcd65dd9ba1c7L341). It will search extra folders for compiler rt builtin libraries. But in tests, OHOS::getCompilerRT()'s return value will not be changed, becasue those extra folders don't have those requested builtin files. It will just returns the default library file path. https://github.com/llvm/llvm-project/pull/120159 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][transformer] Allow usage of applyFirst with rewriteDescendants (PR #117658)
SherAndrei wrote: > Will any of the new tests trigger the bug? Yes, two of them do fail if no suggested changes are present. Feel free to reproduce it yourself. ```bash ./tools/clang/unittests/Tooling/ToolingTests --gtest_filter=*Transform*RewriteDescendantsApplyFirst* ``` yields ```diff Note: Google Test filter = *Transform*RewriteDescendantsApplyFirst* [==] Running 3 tests from 1 test suite. [--] Global test environment set-up. [--] 3 tests from TransformerTest [ RUN ] TransformerTest.RewriteDescendantsApplyFirstOrderedRuleUnrelated /root/clang-llvm/llvm-project/clang/unittests/Tooling/TransformerTest.cpp:94: Failure Expected equality of these values: format(Expected) Which is: "int f(int x) {\n char y = 3;\n return 3;\n}" format(Actual) Which is: "int f(int x) {\n 3 y = 3;\n return 3;\n}" With diff: @@ -1,4 +1,4 @@ int f(int x) { - char y = 3; + 3 y = 3; return 3; } [ FAILED ] TransformerTest.RewriteDescendantsApplyFirstOrderedRuleUnrelated (17 ms) [ RUN ] TransformerTest.RewriteDescendantsApplyFirstOrderedRuleRelated /root/clang-llvm/llvm-project/clang/unittests/Tooling/TransformerTest.cpp:94: Failure Expected equality of these values: format(Expected) Which is: "int f(int x) {\n int y = 3;\n return y;\n}" format(Actual) Which is: "int f(int x) {\n int y = y;\n return y;\n}" With diff: @@ -1,4 +1,4 @@ int f(int x) { - int y = 3; + int y = y; return y; } [ FAILED ] TransformerTest.RewriteDescendantsApplyFirstOrderedRuleRelated (14 ms) [ RUN ] TransformerTest.RewriteDescendantsApplyFirstOrderedRuleRelatedSwapped [ OK ] TransformerTest.RewriteDescendantsApplyFirstOrderedRuleRelatedSwapped (13 ms) [--] 3 tests from TransformerTest (45 ms total) [--] Global test environment tear-down [==] 3 tests from 1 test suite ran. (45 ms total) [ PASSED ] 1 test. [ FAILED ] 2 tests, listed below: [ FAILED ] TransformerTest.RewriteDescendantsApplyFirstOrderedRuleUnrelated [ FAILED ] TransformerTest.RewriteDescendantsApplyFirstOrderedRuleRelated 2 FAILED TESTS ``` > Can you clarify where the matchers associated with the nested rule will be > shifted? As far as I can tell, the original match uses Tag0 but happens in a > separate context (that is, MatchFinder) than the nested match so I don't see > how they are interacting. Yes, indeed the original match happens in separate context, but all contexts share one `NodesMap`, which values are overriden with a consecutive match ('clash'). Let's consider test `RewriteDescendantsApplyFirstOrderedRuleUnrelated` before suggested changes: 1. `Transformer::registerMatchers` calls to `taggedMatchers`: `FunctionDecl` matcher, we'll call it FD, receives "Tag0", 2. then `ApplyRuleCallback::registerMatchers` calls to `taggedMatchers`: first `DeclRefExpr` matcher, let's call it DRE1, receives "Tag0", second `DeclRefExpr` matcher -- DRE2 -- receives "Tag1", 3. when DRE1 matches, `ApplyRuleCallback::run` calls to `findSelectedCase`: it successfully finds "Tag0" which is bound to FD and not to expected DRE1. Now let's consider same test with suggested changes 1. `Transformer::registerMatchers` binds FD to "Tag93825274205568", 2. `ApplyRuleCallback::registerMatchers` binds DRE1 to "Tag93825274195136", DRE2 to "Tag93825274196288", 3. when DRE1 matches, `findSelectedCase` finds expected DRE1 by searching for "Tag93825274195136" Sorry for misleading you by using the word 'shifted' here. Nothing is shifted here really. I do struggle to update description of the commit. What do you think about next description of the commit: ``` [clang][transformer] Allow usage of applyFirst with rewriteDescendants Previously,, `taggedMatchers` could apply same tag to two different matchers (here, for enclosing matcher and for first from `applyFirst`). We fix this by making sure that associated Tags are unique and deterministic as they are intend to be. ``` https://github.com/llvm/llvm-project/pull/117658 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)
@@ -11077,6 +11077,281 @@ TEST_F(FormatTest, WrapsTemplateDeclarationsWithComments) { Style); } +TEST_F(FormatTest, BreakBeforeTemplateClose) { + FormatStyle Style = getGoogleStyle(FormatStyle::LK_Cpp); + Style.ColumnLimit = 0; + verifyNoChange("template \n" + "void foo() {}", + Style); + verifyNoChange("template <\n" + "typename Foo,\n" + "typename Bar>\n" + "void foo() {}", + Style); + // when BreakBeforeTemplateClose is off, this line break is removed: + verifyFormat("template <\n" + "typename Foo,\n" + "typename Bar>\n" + "void foo() {}", + "template <\n" + "typename Foo,\n" + "typename Bar\n" + ">\n" + "void foo() {}", + Style); + Style.BreakBeforeTemplateClose = true; + // BreakBeforeTemplateClose should NOT force multiline templates + verifyNoChange("template \n" + "void foo() {}", + Style); + verifyNoChange("template \n" + "void foo() {}", + Style); + // it should allow a line break: + verifyNoChange("template <\n" + "typename Foo\n" + ">\n" + "void foo() {}", + Style); + verifyNoChange("template <\n" + "typename Foo,\n" + "typename Bar\n" + ">\n" + "void foo() {}", + Style); + // it should add a line break if not already present: + verifyFormat("template <\n" + "typename Foo\n" + ">\n" + "void foo() {}", + "template <\n" + "typename Foo>\n" + "void foo() {}", + Style); + verifyFormat("template <\n" + "typename Foo,\n" + "typename Bar\n" + ">\n" + "void foo() {}", + "template <\n" + "typename Foo,\n" + "typename Bar>\n" + "void foo() {}", + Style); + // when within an indent scope, the > should be placed appropriately: + verifyFormat("struct Baz {\n" + " template <\n" + " typename Foo,\n" + " typename Bar\n" + " >\n" + " void foo() {}\n" + "};", + "struct Baz {\n" + " template <\n" + " typename Foo,\n" + " typename Bar>\n" + " void foo() {}\n" + "};", + Style); + + // test from issue #80049 + verifyFormat( + "void foo() {\n" + " using type = std::remove_cv_t<\n" + " add_common_cv_reference<\n" + " std::common_type_t, std::decay_t>,\n" + " T0,\n" + " T1\n" + " >\n" + " >;\n" + "}\n", + "void foo() {\n" + " using type = std::remove_cv_t<\n" + " add_common_cv_reference<\n" + " std::common_type_t, std::decay_t>,\n" + " T0,\n" + " T1>>;\n" + "}\n", + Style); + + // test lambda goes to next line: + verifyFormat("void foo() {\n" + " auto lambda = []<\n" + "typename T\n" + ">(T t) {\n" + " };\n" + "}\n", + "void foo() {\n" + " auto lambda = []<\n" + " typename T>(T t){\n" + " };\n" + "}\n", + Style); + // with no column limit, two parameters can go on the same line: + verifyFormat("void foo() {\n" + " auto lambda = []<\n" + "typename T, typename Foo\n" + ">(T t) {\n" + " };\n" + "}\n", + "void foo() {\n" + " auto lambda = []<\n" + " typename T, typename Foo>(T t){\n" + " };\n" + "}\n", + Style); + // or on different lines: + verifyFormat("void foo() {\n" + " auto lambda = []<\n" + "typename T,\n" + "typename Foo\n" + ">(T t) {\n" + " };\n" + "}\n", + "void foo() {\n" + " auto lambda = []<\n" + " typename T,\n" + " typename Foo>(T t){\n" + " };\n" + "}\n", + Style); + + // same line with no column limit + verifyFormat("void foo() {\n" + " auto lambda = [](" + "Long t) {};\n" + "}\n", + Sty
[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)
@@ -11077,6 +11077,281 @@ TEST_F(FormatTest, WrapsTemplateDeclarationsWithComments) { Style); } +TEST_F(FormatTest, BreakBeforeTemplateClose) { + FormatStyle Style = getGoogleStyle(FormatStyle::LK_Cpp); + Style.ColumnLimit = 0; + verifyNoChange("template \n" + "void foo() {}", + Style); + verifyNoChange("template <\n" + "typename Foo,\n" + "typename Bar>\n" + "void foo() {}", + Style); + // when BreakBeforeTemplateClose is off, this line break is removed: + verifyFormat("template <\n" + "typename Foo,\n" + "typename Bar>\n" + "void foo() {}", + "template <\n" + "typename Foo,\n" + "typename Bar\n" + ">\n" + "void foo() {}", + Style); + Style.BreakBeforeTemplateClose = true; + // BreakBeforeTemplateClose should NOT force multiline templates + verifyNoChange("template \n" + "void foo() {}", + Style); + verifyNoChange("template \n" + "void foo() {}", + Style); + // it should allow a line break: + verifyNoChange("template <\n" + "typename Foo\n" + ">\n" + "void foo() {}", + Style); + verifyNoChange("template <\n" + "typename Foo,\n" + "typename Bar\n" + ">\n" + "void foo() {}", + Style); + // it should add a line break if not already present: + verifyFormat("template <\n" + "typename Foo\n" + ">\n" + "void foo() {}", + "template <\n" + "typename Foo>\n" + "void foo() {}", + Style); + verifyFormat("template <\n" + "typename Foo,\n" + "typename Bar\n" + ">\n" + "void foo() {}", + "template <\n" + "typename Foo,\n" + "typename Bar>\n" + "void foo() {}", + Style); + // when within an indent scope, the > should be placed appropriately: + verifyFormat("struct Baz {\n" + " template <\n" + " typename Foo,\n" + " typename Bar\n" + " >\n" + " void foo() {}\n" + "};", + "struct Baz {\n" + " template <\n" + " typename Foo,\n" + " typename Bar>\n" + " void foo() {}\n" + "};", + Style); + + // test from issue #80049 + verifyFormat( + "void foo() {\n" + " using type = std::remove_cv_t<\n" + " add_common_cv_reference<\n" + " std::common_type_t, std::decay_t>,\n" + " T0,\n" + " T1\n" + " >\n" + " >;\n" + "}\n", + "void foo() {\n" + " using type = std::remove_cv_t<\n" + " add_common_cv_reference<\n" + " std::common_type_t, std::decay_t>,\n" + " T0,\n" + " T1>>;\n" + "}\n", + Style); + + // test lambda goes to next line: + verifyFormat("void foo() {\n" + " auto lambda = []<\n" + "typename T\n" + ">(T t) {\n" + " };\n" + "}\n", + "void foo() {\n" + " auto lambda = []<\n" + " typename T>(T t){\n" + " };\n" + "}\n", + Style); + // with no column limit, two parameters can go on the same line: + verifyFormat("void foo() {\n" + " auto lambda = []<\n" + "typename T, typename Foo\n" + ">(T t) {\n" + " };\n" + "}\n", + "void foo() {\n" + " auto lambda = []<\n" + " typename T, typename Foo>(T t){\n" + " };\n" + "}\n", + Style); + // or on different lines: + verifyFormat("void foo() {\n" + " auto lambda = []<\n" + "typename T,\n" + "typename Foo\n" + ">(T t) {\n" + " };\n" + "}\n", + "void foo() {\n" + " auto lambda = []<\n" + " typename T,\n" + " typename Foo>(T t){\n" + " };\n" + "}\n", + Style); + + // same line with no column limit + verifyFormat("void foo() {\n" + " auto lambda = [](" + "Long t) {};\n" + "}\n", + Sty
[clang] fix(clang/**.py): fix invalid escape sequences (PR #94029)
https://github.com/e-kwsm updated https://github.com/llvm/llvm-project/pull/94029 >From 511dda8045630f775d96805510f730aebbfc3680 Mon Sep 17 00:00:00 2001 From: Eisuke Kawashima Date: Sat, 11 May 2024 02:39:21 +0900 Subject: [PATCH] fix(clang/**.py): fix invalid escape sequences --- clang/docs/tools/dump_ast_matchers.py | 10 +- clang/test/Analysis/check-analyzer-fixit.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clang/docs/tools/dump_ast_matchers.py b/clang/docs/tools/dump_ast_matchers.py index b6f00657ec914c..c94a533f4c68f2 100755 --- a/clang/docs/tools/dump_ast_matchers.py +++ b/clang/docs/tools/dump_ast_matchers.py @@ -91,11 +91,11 @@ def extract_result_types(comment): parsed. """ result_types = [] -m = re.search(r"Usable as: Any Matcher[\s\n]*$", comment, re.S) +m = re.search("Usable as: Any Matcher[\\s\n]*$", comment, re.S) if m: return ["*"] while True: -m = re.match(r"^(.*)Matcher<([^>]+)>\s*,?[\s\n]*$", comment, re.S) +m = re.match("^(.*)Matcher<([^>]+)>\\s*,?[\\s\n]*$", comment, re.S) if not m: if re.search(r"Usable as:\s*$", comment): return result_types @@ -106,9 +106,9 @@ def extract_result_types(comment): def strip_doxygen(comment): -"""Returns the given comment without \-escaped words.""" +r"""Returns the given comment without \-escaped words.""" # If there is only a doxygen keyword in the line, delete the whole line. -comment = re.sub(r"^\\[^\s]+\n", r"", comment, flags=re.M) +comment = re.sub("^[^\\s]+\n", r"", comment, flags=re.M) # If there is a doxygen \see command, change the \see prefix into "See also:". # FIXME: it would be better to turn this into a link to the target instead. @@ -241,7 +241,7 @@ def act_on_decl(declaration, comment, allowed_types): # Parse the various matcher definition macros. m = re.match( -""".*AST_TYPE(LOC)?_TRAVERSE_MATCHER(?:_DECL)?\( +r""".*AST_TYPE(LOC)?_TRAVERSE_MATCHER(?:_DECL)?\( \s*([^\s,]+\s*), \s*(?:[^\s,]+\s*), \s*AST_POLYMORPHIC_SUPPORTED_TYPES\(([^)]*)\) diff --git a/clang/test/Analysis/check-analyzer-fixit.py b/clang/test/Analysis/check-analyzer-fixit.py index b616255de89b0c..43968f4b1b6e8d 100644 --- a/clang/test/Analysis/check-analyzer-fixit.py +++ b/clang/test/Analysis/check-analyzer-fixit.py @@ -55,7 +55,7 @@ def run_test_once(args, extra_args): # themselves. We need to keep the comments to preserve line numbers while # avoiding empty lines which could potentially trigger formatting-related # checks. -cleaned_test = re.sub("// *CHECK-[A-Z0-9\-]*:[^\r\n]*", "//", input_text) +cleaned_test = re.sub("// *CHECK-[A-Z0-9\\-]*:[^\r\n]*", "//", input_text) write_file(temp_file_name, cleaned_test) original_file_name = temp_file_name + ".orig" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add float type support to __builtin_reduce_add and __builtin_reduce_multipy (PR #120367)
@@ -4274,12 +4274,37 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, *this, E, GetIntrinsicID(E->getArg(0)->getType()), "rdx.min")); } - case Builtin::BI__builtin_reduce_add: + case Builtin::BI__builtin_reduce_add: { +// Note: vector_reduce_fadd takes two arguments a +// scalar start value and a vector. That would mean to +// correctly call it we would need emitBuiltinWithOneOverloadedType<2> +// To keep the builtin sema behavior the same despite type we will +// popululate vector_reduce_fadd scalar value with a 0. +if (E->getArg(0)->getType()->hasFloatingRepresentation()) { + Value *X = EmitScalarExpr(E->getArg(0)); + auto EltTy = X->getType()->getScalarType(); + Value *Seed = ConstantFP::get(EltTy, 0); + return RValue::get(Builder.CreateIntrinsic( + /*ReturnType=*/EltTy, llvm::Intrinsic::vector_reduce_fadd, + ArrayRef{Seed, X}, nullptr, "rdx.fadd")); +} +assert(E->getArg(0)->getType()->hasIntegerRepresentation()); return RValue::get(emitBuiltinWithOneOverloadedType<1>( *this, E, llvm::Intrinsic::vector_reduce_add, "rdx.add")); - case Builtin::BI__builtin_reduce_mul: + } + case Builtin::BI__builtin_reduce_mul: { +if (E->getArg(0)->getType()->hasFloatingRepresentation()) { + Value *X = EmitScalarExpr(E->getArg(0)); + auto EltTy = X->getType()->getScalarType(); + Value *Seed = ConstantFP::get(EltTy, 0); Il-Capitano wrote: Use `1.0` as the initial value. https://github.com/llvm/llvm-project/pull/120367 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add float type support to __builtin_reduce_add and __builtin_reduce_multipy (PR #120367)
@@ -4274,12 +4274,37 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, *this, E, GetIntrinsicID(E->getArg(0)->getType()), "rdx.min")); } - case Builtin::BI__builtin_reduce_add: + case Builtin::BI__builtin_reduce_add: { +// Note: vector_reduce_fadd takes two arguments a +// scalar start value and a vector. That would mean to +// correctly call it we would need emitBuiltinWithOneOverloadedType<2> +// To keep the builtin sema behavior the same despite type we will +// popululate vector_reduce_fadd scalar value with a 0. +if (E->getArg(0)->getType()->hasFloatingRepresentation()) { + Value *X = EmitScalarExpr(E->getArg(0)); + auto EltTy = X->getType()->getScalarType(); + Value *Seed = ConstantFP::get(EltTy, 0); Il-Capitano wrote: Use `-0.0` as the initial value, as that's the neutral additive float, i.e. `-0.0 + x == x`. This can have an effect on code generation, see for example https://github.com/rust-lang/rust/issues/130028. https://github.com/llvm/llvm-project/pull/120367 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add float type support to __builtin_reduce_add and __builtin_reduce_multipy (PR #120367)
https://github.com/Il-Capitano edited https://github.com/llvm/llvm-project/pull/120367 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 70965ef - [Clang] Prevent assignment to captured structured bindings inside immutable lambda (#120849)
Author: TilakChad Date: 2024-12-25T18:59:33+01:00 New Revision: 70965ef259a161a6e9ccfb8bd841dd2246c56c37 URL: https://github.com/llvm/llvm-project/commit/70965ef259a161a6e9ccfb8bd841dd2246c56c37 DIFF: https://github.com/llvm/llvm-project/commit/70965ef259a161a6e9ccfb8bd841dd2246c56c37.diff LOG: [Clang] Prevent assignment to captured structured bindings inside immutable lambda (#120849) For structured bindings, a call to getCapturedDeclRefType(...) was missing. This PR fixes that behavior and adds the related diagnostics too. This fixes https://github.com/llvm/llvm-project/issues/95081. Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaExpr.cpp clang/test/SemaCXX/cxx20-decomposition.cpp Removed: diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index d9b0cb815a15db..4410b9f99e802f 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -885,6 +885,7 @@ Bug Fixes to C++ Support - Fixed recognition of ``std::initializer_list`` when it's surrounded with ``extern "C++"`` and exported out of a module (which is the case e.g. in MSVC's implementation of ``std`` module). (#GH118218) - Fixed a pack expansion issue in checking unexpanded parameter sizes. (#GH17042) +- Fixed a bug where captured structured bindings were modifiable inside non-mutable lambda (#GH95081) Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 24f7d27c691154..562c98c6babe04 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -3352,6 +3352,7 @@ ExprResult Sema::BuildDeclarationNameExpr( case Decl::VarTemplateSpecialization: case Decl::VarTemplatePartialSpecialization: case Decl::Decomposition: + case Decl::Binding: case Decl::OMPCapturedExpr: // In C, "extern void blah;" is valid and is an r-value. if (!getLangOpts().CPlusPlus && !type.hasQualifiers() && @@ -3371,20 +3372,13 @@ ExprResult Sema::BuildDeclarationNameExpr( // potentially-evaluated contexts? Since the variable isn't actually // captured in an unevaluated context, it seems that the answer is no. if (!isUnevaluatedContext()) { - QualType CapturedType = getCapturedDeclRefType(cast(VD), Loc); + QualType CapturedType = getCapturedDeclRefType(cast(VD), Loc); if (!CapturedType.isNull()) type = CapturedType; } - break; } - case Decl::Binding: -// These are always lvalues. -valueKind = VK_LValue; -type = type.getNonReferenceType(); -break; - case Decl::Function: { if (unsigned BID = cast(VD)->getBuiltinID()) { if (!Context.BuiltinInfo.isDirectlyAddressable(BID)) { @@ -13297,11 +13291,24 @@ static NonConstCaptureKind isReferenceToNonConstCapture(Sema &S, Expr *E) { if (!DRE) return NCCK_None; if (!DRE->refersToEnclosingVariableOrCapture()) return NCCK_None; - // The declaration must be a variable which is not declared 'const'. - VarDecl *var = dyn_cast(DRE->getDecl()); - if (!var) return NCCK_None; - if (var->getType().isConstQualified()) return NCCK_None; - assert(var->hasLocalStorage() && "capture added 'const' to non-local?"); + ValueDecl *Value = dyn_cast(DRE->getDecl()); + + // The declaration must be a value which is not declared 'const'. + if (!Value || Value->getType().isConstQualified()) +return NCCK_None; + + BindingDecl *Binding = dyn_cast(Value); + if (Binding) { +assert(S.getLangOpts().CPlusPlus && "BindingDecl outside of C++?"); +assert(!isa(Binding->getDeclContext())); +return NCCK_Lambda; + } + + VarDecl *Var = dyn_cast(Value); + if (!Var) +return NCCK_None; + + assert(Var->hasLocalStorage() && "capture added 'const' to non-local?"); // Decide whether the first capture was for a block or a lambda. DeclContext *DC = S.CurContext, *Prev = nullptr; @@ -13310,16 +13317,16 @@ static NonConstCaptureKind isReferenceToNonConstCapture(Sema &S, Expr *E) { // For init-capture, it is possible that the variable belongs to the // template pattern of the current context. if (auto *FD = dyn_cast(DC)) - if (var->isInitCapture() && - FD->getTemplateInstantiationPattern() == var->getDeclContext()) + if (Var->isInitCapture() && + FD->getTemplateInstantiationPattern() == Var->getDeclContext()) break; -if (DC == var->getDeclContext()) +if (DC == Var->getDeclContext()) break; Prev = DC; DC = DC->getParent(); } // Unless we have an init-capture, we've gone one step too far. - if (!var->isInitCapture()) + if (!Var->isInitCapture()) DC = Prev; return (isa(DC) ? NCCK_Block : NCCK_Lambda); } @@ -19247,6 +19254,8 @@ bool Sema::NeedToCaptureVariable(ValueDecl *Var, SourceLocation Loc) { } QualType Sema::getCapturedDeclRefType(ValueDecl *Var, SourceLocation Lo
[clang] [Clang] Prevent assignment to captured structured bindings inside immutable lambda (PR #120849)
https://github.com/cor3ntin closed https://github.com/llvm/llvm-project/pull/120849 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Prevent assignment to captured structured bindings inside immutable lambda (PR #120849)
github-actions[bot] wrote: @TilakChad Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail [here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr). If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of [LLVM development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy). You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! https://github.com/llvm/llvm-project/pull/120849 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Driver][Test] Created test for unsupported driver options (PR #120900)
Maetveis wrote: > @Maetveis > > All of the Visibility fields appear to be not null, but that's a good check > to add anyway. Thanks. After adding it though, the same failures occur. > Here's an example. Maybe there's a gap in my understanding: > > The script generates tests for both flang & clang -cc1as when looking at the > O_flag option. cc1as outputs the unexpected error message, but flang does not. That looks to be by design, because you are using the `-help`, the drivers meant to be user facing (clang, clang-cl and flang) don't report unknown options with `-help`. A user might tack on a `-help` after their broken command line when they are looking for the exact spelling of their option so it makes sense that it is not an error to have unknown options when mixed with `-help`. Simply you shouldn't be using `-help`, instead passing options to perform a real compilation on the command line like `clang-cl -### -x c++ -c - < /dev/null` should work better. The other issues is that `-O_flag` is parsed as `-O _flag` for drivers that support `-O`, in runtime longer valid options have preference over shorter ones, in this case I think if there is a supported joined option (`Kind == JoinedClass`) that is a prefix of an unsupported option you now way to test the unsupported option so it should be skipped. https://github.com/llvm/llvm-project/pull/120900 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Prevent assignment to captured structured bindings inside immutable lambda (PR #120849)
https://github.com/cor3ntin approved this pull request. LGTM, thanks https://github.com/llvm/llvm-project/pull/120849 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)
@@ -11077,6 +11077,281 @@ TEST_F(FormatTest, WrapsTemplateDeclarationsWithComments) { Style); } +TEST_F(FormatTest, BreakBeforeTemplateClose) { + FormatStyle Style = getGoogleStyle(FormatStyle::LK_Cpp); + Style.ColumnLimit = 0; + verifyNoChange("template \n" + "void foo() {}", + Style); + verifyNoChange("template <\n" + "typename Foo,\n" + "typename Bar>\n" + "void foo() {}", + Style); + // when BreakBeforeTemplateClose is off, this line break is removed: + verifyFormat("template <\n" + "typename Foo,\n" + "typename Bar>\n" + "void foo() {}", + "template <\n" + "typename Foo,\n" + "typename Bar\n" + ">\n" + "void foo() {}", + Style); + Style.BreakBeforeTemplateClose = true; + // BreakBeforeTemplateClose should NOT force multiline templates + verifyNoChange("template \n" + "void foo() {}", + Style); + verifyNoChange("template \n" + "void foo() {}", + Style); + // it should allow a line break: + verifyNoChange("template <\n" + "typename Foo\n" + ">\n" + "void foo() {}", + Style); + verifyNoChange("template <\n" + "typename Foo,\n" + "typename Bar\n" + ">\n" + "void foo() {}", + Style); + // it should add a line break if not already present: + verifyFormat("template <\n" + "typename Foo\n" + ">\n" + "void foo() {}", + "template <\n" + "typename Foo>\n" + "void foo() {}", + Style); + verifyFormat("template <\n" + "typename Foo,\n" + "typename Bar\n" + ">\n" + "void foo() {}", + "template <\n" + "typename Foo,\n" + "typename Bar>\n" + "void foo() {}", + Style); + // when within an indent scope, the > should be placed appropriately: + verifyFormat("struct Baz {\n" + " template <\n" + " typename Foo,\n" + " typename Bar\n" + " >\n" + " void foo() {}\n" + "};", + "struct Baz {\n" + " template <\n" + " typename Foo,\n" + " typename Bar>\n" + " void foo() {}\n" + "};", + Style); + + // test from issue #80049 + verifyFormat( + "void foo() {\n" + " using type = std::remove_cv_t<\n" + " add_common_cv_reference<\n" + " std::common_type_t, std::decay_t>,\n" + " T0,\n" + " T1\n" + " >\n" + " >;\n" + "}\n", + "void foo() {\n" + " using type = std::remove_cv_t<\n" + " add_common_cv_reference<\n" + " std::common_type_t, std::decay_t>,\n" + " T0,\n" + " T1>>;\n" + "}\n", + Style); + + // test lambda goes to next line: + verifyFormat("void foo() {\n" + " auto lambda = []<\n" + "typename T\n" + ">(T t) {\n" + " };\n" + "}\n", + "void foo() {\n" + " auto lambda = []<\n" + " typename T>(T t){\n" + " };\n" + "}\n", + Style); + // with no column limit, two parameters can go on the same line: + verifyFormat("void foo() {\n" + " auto lambda = []<\n" + "typename T, typename Foo\n" + ">(T t) {\n" + " };\n" + "}\n", + "void foo() {\n" + " auto lambda = []<\n" + " typename T, typename Foo>(T t){\n" + " };\n" + "}\n", + Style); + // or on different lines: + verifyFormat("void foo() {\n" + " auto lambda = []<\n" + "typename T,\n" + "typename Foo\n" + ">(T t) {\n" + " };\n" + "}\n", + "void foo() {\n" + " auto lambda = []<\n" + " typename T,\n" + " typename Foo>(T t){\n" + " };\n" + "}\n", + Style); + + // same line with no column limit + verifyFormat("void foo() {\n" + " auto lambda = [](" + "Long t) {};\n" + "}\n", + Sty
[clang] [compiler-rt] [Ubsan][Driver] Remove UBSAN C++ runtime from other sanitizers (PR #121006)
mstorsjo wrote: This change broke compiler-rt tests on mingw/i686 - have a look: https://github.com/mstorsjo/llvm-mingw/actions/runs/12487763901/job/34855514237 I haven't had time to dig in to understand what's really happening here, but I have pinpointed the failures to this specific commit by rerunning a similar build+test pipeline both with this commit and the preceding one. https://github.com/llvm/llvm-project/pull/121006 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC][Driver] Use global --implicit-check-not=libclang_rt (PR #121081)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/121081 >From 75aa55a129dd1311a889a9bb4b0f4ee04206d157 Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Tue, 24 Dec 2024 19:38:02 -0800 Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?= =?UTF-8?q?l=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.4 --- clang/test/Driver/sanitizer-ld.c | 303 ++- 1 file changed, 174 insertions(+), 129 deletions(-) diff --git a/clang/test/Driver/sanitizer-ld.c b/clang/test/Driver/sanitizer-ld.c index 8f2f7a5997ab4a..0c36da1773c9f1 100644 --- a/clang/test/Driver/sanitizer-ld.c +++ b/clang/test/Driver/sanitizer-ld.c @@ -1,14 +1,17 @@ // Test sanitizers ld flags. +// RUN: export FILECHECK_OPTS="--implicit-check-not=\"/libclang_rt\"" + // RUN: %clang -### %s 2>&1 \ // RUN: --target=i386-unknown-linux -fuse-ld=ld -fsanitize=address \ // RUN: -resource-dir=%S/Inputs/resource_dir \ // RUN: --sysroot=%S/Inputs/basic_linux_tree \ // RUN: | FileCheck --check-prefix=CHECK-ASAN-LINUX %s // -// CHECK-ASAN-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}" +// CHECK-ASAN-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld" // CHECK-ASAN-LINUX-NOT: "-lc" -// CHECK-ASAN-LINUX: libclang_rt.asan.a" +// CHECK-ASAN-LINUX: "--whole-archive" "{{.*}}libclang_rt.asan_static.a" "--no-whole-archive" +// CHECK-ASAN-LINUX: "--whole-archive" "{{.*}}libclang_rt.asan.a" "--no-whole-archive" // CHECK-ASAN-LINUX-NOT: "--export-dynamic" // CHECK-ASAN-LINUX: "--dynamic-list={{.*}}libclang_rt.asan.a.syms" // CHECK-ASAN-LINUX-NOT: "--export-dynamic" @@ -23,17 +26,16 @@ // RUN: --sysroot=%S/Inputs/basic_linux_tree \ // RUN: | FileCheck --check-prefix=CHECK-ASAN-NO-LINK-RUNTIME-LINUX %s // -// CHECK-ASAN-NO-LINK-RUNTIME-LINUX-NOT: libclang_rt.asan_static-x86_64 -// CHECK-ASAN-NO-LINK-RUNTIME-LINUX-NOT: libclang_rt.asan-x86_64 +// CHECK-ASAN-NO-LINK-RUNTIME-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld" -// RUN: %clang -fsanitize=address -fno-sanitize-link-runtime -### %s 2>&1 \ +// RUN: %clang -fsanitize=address -fsanitize-link-runtime -### %s 2>&1 \ // RUN: --target=arm64e-apple-macosx -fuse-ld=ld \ // RUN: -resource-dir=%S/Inputs/resource_dir \ // RUN: --sysroot=%S/Inputs/basic_linux_tree \ // RUN: | FileCheck --check-prefix=CHECK-ASAN-NO-LINK-RUNTIME-DARWIN %s // -// CHECK-ASAN-NO-LINK-RUNTIME-DARWIN-NOT: libclang_rt.asan_static -// CHECK-ASAN-NO-LINK-RUNTIME-DARWIN-NOT: libclang_rt.asan +// CHECK-ASAN-NO-LINK-RUNTIME-DARWIN: /libclang_rt.asan_osx_dynamic.dylib +// CHECK-ASAN-NO-LINK-RUNTIME-DARWIN: /libclang_rt.osx.a // RUN: %clang -fsanitize=address -### %s 2>&1 \ // RUN: --target=x86_64-unknown-linux -fuse-ld=ld \ @@ -41,8 +43,9 @@ // RUN: --sysroot=%S/Inputs/basic_linux_tree \ // RUN: | FileCheck --check-prefix=CHECK-ASAN-EXECUTABLE-LINUX %s // -// CHECK-ASAN-EXECUTABLE-LINUX: libclang_rt.asan_static -// CHECK-ASAN-EXECUTABLE-LINUX: libclang_rt.asan +// CHECK-ASAN-EXECUTABLE-LINUX: "--whole-archive" "{{.*}}libclang_rt.asan_static.a" "--no-whole-archive" +// CHECK-ASAN-EXECUTABLE-LINUX: "--whole-archive" "{{.*}}libclang_rt.asan.a" "--no-whole-archive" +// CHECK-ASAN-EXECUTABLE-LINUX: "--dynamic-list={{.*}}libclang_rt.asan.a.syms" // RUN: %clang -fsanitize=address -shared -### %s 2>&1 \ // RUN: --target=x86_64-unknown-linux -fuse-ld=ld \ @@ -51,7 +54,6 @@ // RUN: | FileCheck --check-prefix=CHECK-ASAN-SHARED-LINUX %s // // CHECK-ASAN-SHARED-LINUX: libclang_rt.asan_static -// CHECK-ASAN-SHARED-LINUX-NOT: libclang_rt.asan // RUN: %clang -### %s 2>&1 \ // RUN: --target=i386-unknown-linux -fuse-ld=ld -fsanitize=address -shared-libsan \ @@ -72,11 +74,11 @@ // RUN: --sysroot=%S/Inputs/basic_linux_tree \ // RUN: | FileCheck --check-prefix=CHECK-SHARED-ASAN-LINUX %s // -// CHECK-SHARED-ASAN-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}" +// CHECK-SHARED-ASAN-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld" // CHECK-SHARED-ASAN-LINUX-NOT: "-lc" -// CHECK-SHARED-ASAN-LINUX-NOT: libclang_rt.asan.a" // CHECK-SHARED-ASAN-LINUX: libclang_rt.asan.so" // CHECK-SHARED-ASAN-LINUX: "--whole-archive" "{{.*}}libclang_rt.asan-preinit.a" "--no-whole-archive" +// CHECK-SHARED-ASAN-LINUX: "--whole-archive" "{{.*}}libclang_rt.asan_static.a" "--no-whole-archive" // CHECK-SHARED-ASAN-LINUX-NOT: "-lpthread" // CHECK-SHARED-ASAN-LINUX-NOT: "-lrt" // CHECK-SHARED-ASAN-LINUX-NOT: "-ldl" @@ -90,11 +92,10 @@ // RUN: --sysroot=%S/Inputs/basic_linux_tree \ // RUN: | FileCheck --check-prefix=CHECK-DSO-SHARED-ASAN-LINUX %s // -// CHECK-DSO-SHARED-ASAN-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}" +// CHECK-DSO-SHARED-ASAN-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld" // CHECK-DSO-SHARED-ASAN-LINUX-NOT: "-lc" -// CHECK-DSO-SHARED-ASAN-LINUX-NOT: libclang_rt.asan.a" -// CHECK-DSO-SHARED-ASAN-LINUX-NOT: "libclang_rt.asan-preinit.a" // CHECK-DSO-SHARED-ASAN-LINUX:
[clang] [NFC][Driver] Use global --implicit-check-not=libclang_rt (PR #121081)
https://github.com/MaskRay commented: We should avoid FILECHECK_OPTS. Consider using lit's `DEFINE:` feature. https://github.com/llvm/llvm-project/pull/121081 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [compiler-rt] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` (PR #110366)
https://github.com/zimirza updated https://github.com/llvm/llvm-project/pull/110366 From 24d7d3997bacf06a9add1ab3193d8d0adf2032ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0?= Date: Thu, 26 Dec 2024 08:29:03 +0500 Subject: [PATCH 01/41] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` Closes #107445 --- .../StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp | 4 clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc | 4 clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc | 6 ++ clang/test/Analysis/cert/env34-c.c | 9 - 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp index fefe846b6911f7..9c34d3636c8488 100644 --- a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp @@ -76,6 +76,10 @@ class InvalidPtrChecker &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, {{CDM::CLibrary, {"asctime"}, 1}, &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, + {{CDM::CLibrary, {"ctime"}, 1}, + &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, + {{CDM::CLibrary, {"localtime"}, 1}, + &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, }; // The private members of this checker corresponding to commandline options diff --git a/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc b/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc index 463ce921f0672f..aca22f869b5291 100644 --- a/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc +++ b/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc @@ -220,6 +220,10 @@ SYMBOL(and, None, ) SYMBOL(and_eq, None, ) SYMBOL(asctime, None, ) SYMBOL(asctime_s, None, ) +SYMBOL(ctime, None, ) +SYMBOL(ctime_s, None, ) +SYMBOL(localtime, None, ) +SYMBOL(localtime_s, None, ) SYMBOL(asin, None, ) SYMBOL(asinf, None, ) SYMBOL(asinh, None, ) diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc index c1927180d33976..7a08a5d3beee7a 100644 --- a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc +++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc @@ -618,6 +618,12 @@ SYMBOL(as_writable_bytes, std::, ) SYMBOL(asctime, std::, ) SYMBOL(asctime, None, ) SYMBOL(asctime, None, ) +SYMBOL(ctime, std::, ) +SYMBOL(ctime, None, ) +SYMBOL(ctime, None, ) +SYMBOL(localtime, std::, ) +SYMBOL(localtime, None, ) +SYMBOL(localtime, None, ) SYMBOL(asin, std::, ) SYMBOL(asin, None, ) SYMBOL(asin, None, ) diff --git a/clang/test/Analysis/cert/env34-c.c b/clang/test/Analysis/cert/env34-c.c index d307f0d8f4bb01..66ba0be4a67bba 100644 --- a/clang/test/Analysis/cert/env34-c.c +++ b/clang/test/Analysis/cert/env34-c.c @@ -15,7 +15,14 @@ lconv *localeconv(void); typedef struct { } tm; -char *asctime(const tm *timeptr); +char *asctime(const tm *timeptr) +; +typedef struct { +} tm; +char *ctime(const tm *timeptr); +typedef struct { +} tm; +struct tm *localtime(struct tm *tm); int strcmp(const char*, const char*); extern void foo(char *e); From 6d6f95fc0e25a4e0e0b2ee83b8c60e03fd45674e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0?= Date: Sat, 28 Sep 2024 17:20:00 +0200 Subject: [PATCH 02/41] [clang-tidy] add times to clang-tidy add `ctime` and `localtime` to unsafe functions check function --- clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp index 604a7cac0e4903..f058e5ae40680f 100644 --- a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp @@ -50,6 +50,8 @@ static StringRef getReplacementFor(StringRef FunctionName, StringRef AnnexKReplacementFunction = StringSwitch(FunctionName) .Cases("asctime", "asctime_r", "asctime_s") +.Cases("ctime", "ctime_r") +.Cases("localtime", "localtime_r") .Case("gets", "gets_s") .Default({}); if (!AnnexKReplacementFunction.empty()) From f60bbe61c02f91f287c5e8024ce03e137685ffee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0?= Date: Thu, 26 Dec 2024 08:30:17 +0500 Subject: [PATCH 03/41] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` add changes to release notes --- clang-tools-extra/docs/ReleaseNotes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index fabd0cc78ac6
[clang] [clang-tools-extra] [compiler-rt] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` (PR #110366)
https://github.com/zimirza updated https://github.com/llvm/llvm-project/pull/110366 From 24d7d3997bacf06a9add1ab3193d8d0adf2032ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0?= Date: Thu, 26 Dec 2024 08:29:03 +0500 Subject: [PATCH 01/42] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` Closes #107445 --- .../StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp | 4 clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc | 4 clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc | 6 ++ clang/test/Analysis/cert/env34-c.c | 9 - 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp index fefe846b6911f7..9c34d3636c8488 100644 --- a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp @@ -76,6 +76,10 @@ class InvalidPtrChecker &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, {{CDM::CLibrary, {"asctime"}, 1}, &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, + {{CDM::CLibrary, {"ctime"}, 1}, + &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, + {{CDM::CLibrary, {"localtime"}, 1}, + &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, }; // The private members of this checker corresponding to commandline options diff --git a/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc b/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc index 463ce921f0672f..aca22f869b5291 100644 --- a/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc +++ b/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc @@ -220,6 +220,10 @@ SYMBOL(and, None, ) SYMBOL(and_eq, None, ) SYMBOL(asctime, None, ) SYMBOL(asctime_s, None, ) +SYMBOL(ctime, None, ) +SYMBOL(ctime_s, None, ) +SYMBOL(localtime, None, ) +SYMBOL(localtime_s, None, ) SYMBOL(asin, None, ) SYMBOL(asinf, None, ) SYMBOL(asinh, None, ) diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc index c1927180d33976..7a08a5d3beee7a 100644 --- a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc +++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc @@ -618,6 +618,12 @@ SYMBOL(as_writable_bytes, std::, ) SYMBOL(asctime, std::, ) SYMBOL(asctime, None, ) SYMBOL(asctime, None, ) +SYMBOL(ctime, std::, ) +SYMBOL(ctime, None, ) +SYMBOL(ctime, None, ) +SYMBOL(localtime, std::, ) +SYMBOL(localtime, None, ) +SYMBOL(localtime, None, ) SYMBOL(asin, std::, ) SYMBOL(asin, None, ) SYMBOL(asin, None, ) diff --git a/clang/test/Analysis/cert/env34-c.c b/clang/test/Analysis/cert/env34-c.c index d307f0d8f4bb01..66ba0be4a67bba 100644 --- a/clang/test/Analysis/cert/env34-c.c +++ b/clang/test/Analysis/cert/env34-c.c @@ -15,7 +15,14 @@ lconv *localeconv(void); typedef struct { } tm; -char *asctime(const tm *timeptr); +char *asctime(const tm *timeptr) +; +typedef struct { +} tm; +char *ctime(const tm *timeptr); +typedef struct { +} tm; +struct tm *localtime(struct tm *tm); int strcmp(const char*, const char*); extern void foo(char *e); From 6d6f95fc0e25a4e0e0b2ee83b8c60e03fd45674e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0?= Date: Sat, 28 Sep 2024 17:20:00 +0200 Subject: [PATCH 02/42] [clang-tidy] add times to clang-tidy add `ctime` and `localtime` to unsafe functions check function --- clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp index 604a7cac0e4903..f058e5ae40680f 100644 --- a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp @@ -50,6 +50,8 @@ static StringRef getReplacementFor(StringRef FunctionName, StringRef AnnexKReplacementFunction = StringSwitch(FunctionName) .Cases("asctime", "asctime_r", "asctime_s") +.Cases("ctime", "ctime_r") +.Cases("localtime", "localtime_r") .Case("gets", "gets_s") .Default({}); if (!AnnexKReplacementFunction.empty()) From f60bbe61c02f91f287c5e8024ce03e137685ffee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0?= Date: Thu, 26 Dec 2024 08:30:17 +0500 Subject: [PATCH 03/42] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` add changes to release notes --- clang-tools-extra/docs/ReleaseNotes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index fabd0cc78ac6
[clang] [clang-format][NFC] Make formatting Verilog faster (PR #121139)
https://github.com/sstwcw created https://github.com/llvm/llvm-project/pull/121139 A regular expression was used in the lexing process. It made the program take more than linear time with regards to the length of the input. It looked like the entire buffer could be scanned for every token lexed. Now the regular expression is replaced with code. Previously it took 20 minutes for the program to format 125 000 lines of code on my computer. Now it takes 315 milliseconds. >From e8af860ea0f877862469af5658fa6ad86abc0557 Mon Sep 17 00:00:00 2001 From: sstwcw Date: Thu, 26 Dec 2024 05:14:42 + Subject: [PATCH] [clang-format][NFC] Make formatting Verilog faster A regular expression was used in the lexing process. It made the program take more than linear time with regards to the length of the input. It looked like the entire buffer could be scanned for every token lexed. Now the regular expression is replaced with code. Previously it took 20 minutes for the program to format 125 000 lines of code on my computer. Now it takes 315 milliseconds. --- clang/lib/Format/FormatTokenLexer.cpp | 57 --- clang/unittests/Format/TokenAnnotatorTest.cpp | 34 +++ 2 files changed, 71 insertions(+), 20 deletions(-) diff --git a/clang/lib/Format/FormatTokenLexer.cpp b/clang/lib/Format/FormatTokenLexer.cpp index 7a264bddcdfe19..381b8b9451cbba 100644 --- a/clang/lib/Format/FormatTokenLexer.cpp +++ b/clang/lib/Format/FormatTokenLexer.cpp @@ -1389,34 +1389,51 @@ FormatToken *FormatTokenLexer::getNextToken() { } bool FormatTokenLexer::readRawTokenVerilogSpecific(Token &Tok) { + const char *Start = Lex->getBufferLocation(); + size_t Len; + switch (Start[0]) { // In Verilog the quote is not a character literal. - // + case '\'': +Len = 1; +break; // Make the backtick and double backtick identifiers to match against them // more easily. - // - // In Verilog an escaped identifier starts with backslash and ends with - // whitespace. Unless that whitespace is an escaped newline. A backslash can - // also begin an escaped newline outside of an escaped identifier. We check - // for that outside of the Regex since we can't use negative lookhead - // assertions. Simply changing the '*' to '+' breaks stuff as the escaped - // identifier may have a length of 0 according to Section A.9.3. + case '`': +if (Start[1] == '`') + Len = 2; +else + Len = 1; +break; + // In Verilog an escaped identifier starts with a backslash and ends with + // whitespace. Unless that whitespace is an escaped newline. // FIXME: If there is an escaped newline in the middle of an escaped // identifier, allow for pasting the two lines together, But escaped // identifiers usually occur only in generated code anyway. - static const llvm::Regex VerilogToken(R"re(^('|``?|\\(\\)re" -"(\r?\n|\r)|[^[:space:]])*)"); - - SmallVector Matches; - const char *Start = Lex->getBufferLocation(); - if (!VerilogToken.match(StringRef(Start, Lex->getBuffer().end() - Start), - &Matches)) { + case '\\': +// A backslash can also begin an escaped newline outside of an escaped +// identifier. +if (Start[1] == '\r' || Start[1] == '\n') + return false; +Len = 1; +while (Start[Len] != '\0' && Start[Len] != '\f' && Start[Len] != '\n' && + Start[Len] != '\r' && Start[Len] != '\t' && Start[Len] != '\v' && + Start[Len] != ' ') { + // There is a null byte at the end of the buffer, so we don't have to + // check whether the next byte is within the buffer. + if (Start[Len] == '\\' && Start[Len + 1] == '\r' && + Start[Len + 2] == '\n') { +Len += 3; + } else if (Start[Len] == '\\' && + (Start[Len + 1] == '\r' || Start[Len + 1] == '\n')) { +Len += 2; + } else { +Len += 1; + } +} +break; + default: return false; } - // There is a null byte at the end of the buffer, so we don't have to check - // Start[1] is within the buffer. - if (Start[0] == '\\' && (Start[1] == '\r' || Start[1] == '\n')) -return false; - size_t Len = Matches[0].size(); // The kind has to be an identifier so we can match it against those defined // in Keywords. The kind has to be set before the length because the setLength diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index b2fb5227993c3f..923f6a100d5b39 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -2623,6 +2623,40 @@ TEST_F(TokenAnnotatorTest, UnderstandsVerilogOperators) { "endmodule"); ASSERT_EQ(Tokens.size(), 11u) << Tokens; EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_VerilogMultiLineListLParen); + + // Escaped identifiers. + Tokens = Annotate(R"(\busa+index)"); + ASSERT_EQ(Tokens.size(), 2u) <<
[clang] [clang-format][NFC] Make formatting Verilog faster (PR #121139)
llvmbot wrote: @llvm/pr-subscribers-clang-format Author: None (sstwcw) Changes A regular expression was used in the lexing process. It made the program take more than linear time with regards to the length of the input. It looked like the entire buffer could be scanned for every token lexed. Now the regular expression is replaced with code. Previously it took 20 minutes for the program to format 125 000 lines of code on my computer. Now it takes 315 milliseconds. --- Full diff: https://github.com/llvm/llvm-project/pull/121139.diff 2 Files Affected: - (modified) clang/lib/Format/FormatTokenLexer.cpp (+37-20) - (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+34) ``diff diff --git a/clang/lib/Format/FormatTokenLexer.cpp b/clang/lib/Format/FormatTokenLexer.cpp index 7a264bddcdfe19..381b8b9451cbba 100644 --- a/clang/lib/Format/FormatTokenLexer.cpp +++ b/clang/lib/Format/FormatTokenLexer.cpp @@ -1389,34 +1389,51 @@ FormatToken *FormatTokenLexer::getNextToken() { } bool FormatTokenLexer::readRawTokenVerilogSpecific(Token &Tok) { + const char *Start = Lex->getBufferLocation(); + size_t Len; + switch (Start[0]) { // In Verilog the quote is not a character literal. - // + case '\'': +Len = 1; +break; // Make the backtick and double backtick identifiers to match against them // more easily. - // - // In Verilog an escaped identifier starts with backslash and ends with - // whitespace. Unless that whitespace is an escaped newline. A backslash can - // also begin an escaped newline outside of an escaped identifier. We check - // for that outside of the Regex since we can't use negative lookhead - // assertions. Simply changing the '*' to '+' breaks stuff as the escaped - // identifier may have a length of 0 according to Section A.9.3. + case '`': +if (Start[1] == '`') + Len = 2; +else + Len = 1; +break; + // In Verilog an escaped identifier starts with a backslash and ends with + // whitespace. Unless that whitespace is an escaped newline. // FIXME: If there is an escaped newline in the middle of an escaped // identifier, allow for pasting the two lines together, But escaped // identifiers usually occur only in generated code anyway. - static const llvm::Regex VerilogToken(R"re(^('|``?|\\(\\)re" -"(\r?\n|\r)|[^[:space:]])*)"); - - SmallVector Matches; - const char *Start = Lex->getBufferLocation(); - if (!VerilogToken.match(StringRef(Start, Lex->getBuffer().end() - Start), - &Matches)) { + case '\\': +// A backslash can also begin an escaped newline outside of an escaped +// identifier. +if (Start[1] == '\r' || Start[1] == '\n') + return false; +Len = 1; +while (Start[Len] != '\0' && Start[Len] != '\f' && Start[Len] != '\n' && + Start[Len] != '\r' && Start[Len] != '\t' && Start[Len] != '\v' && + Start[Len] != ' ') { + // There is a null byte at the end of the buffer, so we don't have to + // check whether the next byte is within the buffer. + if (Start[Len] == '\\' && Start[Len + 1] == '\r' && + Start[Len + 2] == '\n') { +Len += 3; + } else if (Start[Len] == '\\' && + (Start[Len + 1] == '\r' || Start[Len + 1] == '\n')) { +Len += 2; + } else { +Len += 1; + } +} +break; + default: return false; } - // There is a null byte at the end of the buffer, so we don't have to check - // Start[1] is within the buffer. - if (Start[0] == '\\' && (Start[1] == '\r' || Start[1] == '\n')) -return false; - size_t Len = Matches[0].size(); // The kind has to be an identifier so we can match it against those defined // in Keywords. The kind has to be set before the length because the setLength diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index b2fb5227993c3f..923f6a100d5b39 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -2623,6 +2623,40 @@ TEST_F(TokenAnnotatorTest, UnderstandsVerilogOperators) { "endmodule"); ASSERT_EQ(Tokens.size(), 11u) << Tokens; EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_VerilogMultiLineListLParen); + + // Escaped identifiers. + Tokens = Annotate(R"(\busa+index)"); + ASSERT_EQ(Tokens.size(), 2u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::identifier, TT_Unknown); + Tokens = Annotate(R"(\busa+index ;)"); + ASSERT_EQ(Tokens.size(), 3u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::identifier, TT_Unknown); + EXPECT_EQ(Tokens[0]->TokenText, R"(\busa+index)"); + EXPECT_TOKEN(Tokens[1], tok::semi, TT_Unknown); + Tokens = Annotate(R"(\busa+index +;)"); + ASSERT_EQ(Tokens.size(), 3u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::identifier, TT_Unknown); + EXPECT_TOKEN(Tokens[1], tok::semi, TT_Unknown); + // The escaped identifier can be
[clang] [clang-tools-extra] [compiler-rt] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` (PR #110366)
https://github.com/zimirza updated https://github.com/llvm/llvm-project/pull/110366 From 24d7d3997bacf06a9add1ab3193d8d0adf2032ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0?= Date: Thu, 26 Dec 2024 08:29:03 +0500 Subject: [PATCH 01/43] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` Closes #107445 --- .../StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp | 4 clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc | 4 clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc | 6 ++ clang/test/Analysis/cert/env34-c.c | 9 - 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp index fefe846b6911f7..9c34d3636c8488 100644 --- a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp @@ -76,6 +76,10 @@ class InvalidPtrChecker &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, {{CDM::CLibrary, {"asctime"}, 1}, &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, + {{CDM::CLibrary, {"ctime"}, 1}, + &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, + {{CDM::CLibrary, {"localtime"}, 1}, + &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, }; // The private members of this checker corresponding to commandline options diff --git a/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc b/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc index 463ce921f0672f..aca22f869b5291 100644 --- a/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc +++ b/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc @@ -220,6 +220,10 @@ SYMBOL(and, None, ) SYMBOL(and_eq, None, ) SYMBOL(asctime, None, ) SYMBOL(asctime_s, None, ) +SYMBOL(ctime, None, ) +SYMBOL(ctime_s, None, ) +SYMBOL(localtime, None, ) +SYMBOL(localtime_s, None, ) SYMBOL(asin, None, ) SYMBOL(asinf, None, ) SYMBOL(asinh, None, ) diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc index c1927180d33976..7a08a5d3beee7a 100644 --- a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc +++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc @@ -618,6 +618,12 @@ SYMBOL(as_writable_bytes, std::, ) SYMBOL(asctime, std::, ) SYMBOL(asctime, None, ) SYMBOL(asctime, None, ) +SYMBOL(ctime, std::, ) +SYMBOL(ctime, None, ) +SYMBOL(ctime, None, ) +SYMBOL(localtime, std::, ) +SYMBOL(localtime, None, ) +SYMBOL(localtime, None, ) SYMBOL(asin, std::, ) SYMBOL(asin, None, ) SYMBOL(asin, None, ) diff --git a/clang/test/Analysis/cert/env34-c.c b/clang/test/Analysis/cert/env34-c.c index d307f0d8f4bb01..66ba0be4a67bba 100644 --- a/clang/test/Analysis/cert/env34-c.c +++ b/clang/test/Analysis/cert/env34-c.c @@ -15,7 +15,14 @@ lconv *localeconv(void); typedef struct { } tm; -char *asctime(const tm *timeptr); +char *asctime(const tm *timeptr) +; +typedef struct { +} tm; +char *ctime(const tm *timeptr); +typedef struct { +} tm; +struct tm *localtime(struct tm *tm); int strcmp(const char*, const char*); extern void foo(char *e); From 6d6f95fc0e25a4e0e0b2ee83b8c60e03fd45674e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0?= Date: Sat, 28 Sep 2024 17:20:00 +0200 Subject: [PATCH 02/43] [clang-tidy] add times to clang-tidy add `ctime` and `localtime` to unsafe functions check function --- clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp index 604a7cac0e4903..f058e5ae40680f 100644 --- a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp @@ -50,6 +50,8 @@ static StringRef getReplacementFor(StringRef FunctionName, StringRef AnnexKReplacementFunction = StringSwitch(FunctionName) .Cases("asctime", "asctime_r", "asctime_s") +.Cases("ctime", "ctime_r") +.Cases("localtime", "localtime_r") .Case("gets", "gets_s") .Default({}); if (!AnnexKReplacementFunction.empty()) From f60bbe61c02f91f287c5e8024ce03e137685ffee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0?= Date: Thu, 26 Dec 2024 08:30:17 +0500 Subject: [PATCH 03/43] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` add changes to release notes --- clang-tools-extra/docs/ReleaseNotes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index fabd0cc78ac6
[clang] [clang-tools-extra] [compiler-rt] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` (PR #110366)
https://github.com/zimirza updated https://github.com/llvm/llvm-project/pull/110366 From 24d7d3997bacf06a9add1ab3193d8d0adf2032ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0?= Date: Thu, 26 Dec 2024 08:29:03 +0500 Subject: [PATCH 01/45] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` Closes #107445 --- .../StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp | 4 clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc | 4 clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc | 6 ++ clang/test/Analysis/cert/env34-c.c | 9 - 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp index fefe846b6911f7..9c34d3636c8488 100644 --- a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp @@ -76,6 +76,10 @@ class InvalidPtrChecker &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, {{CDM::CLibrary, {"asctime"}, 1}, &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, + {{CDM::CLibrary, {"ctime"}, 1}, + &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, + {{CDM::CLibrary, {"localtime"}, 1}, + &InvalidPtrChecker::postPreviousReturnInvalidatingCall}, }; // The private members of this checker corresponding to commandline options diff --git a/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc b/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc index 463ce921f0672f..aca22f869b5291 100644 --- a/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc +++ b/clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc @@ -220,6 +220,10 @@ SYMBOL(and, None, ) SYMBOL(and_eq, None, ) SYMBOL(asctime, None, ) SYMBOL(asctime_s, None, ) +SYMBOL(ctime, None, ) +SYMBOL(ctime_s, None, ) +SYMBOL(localtime, None, ) +SYMBOL(localtime_s, None, ) SYMBOL(asin, None, ) SYMBOL(asinf, None, ) SYMBOL(asinh, None, ) diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc index c1927180d33976..7a08a5d3beee7a 100644 --- a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc +++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc @@ -618,6 +618,12 @@ SYMBOL(as_writable_bytes, std::, ) SYMBOL(asctime, std::, ) SYMBOL(asctime, None, ) SYMBOL(asctime, None, ) +SYMBOL(ctime, std::, ) +SYMBOL(ctime, None, ) +SYMBOL(ctime, None, ) +SYMBOL(localtime, std::, ) +SYMBOL(localtime, None, ) +SYMBOL(localtime, None, ) SYMBOL(asin, std::, ) SYMBOL(asin, None, ) SYMBOL(asin, None, ) diff --git a/clang/test/Analysis/cert/env34-c.c b/clang/test/Analysis/cert/env34-c.c index d307f0d8f4bb01..66ba0be4a67bba 100644 --- a/clang/test/Analysis/cert/env34-c.c +++ b/clang/test/Analysis/cert/env34-c.c @@ -15,7 +15,14 @@ lconv *localeconv(void); typedef struct { } tm; -char *asctime(const tm *timeptr); +char *asctime(const tm *timeptr) +; +typedef struct { +} tm; +char *ctime(const tm *timeptr); +typedef struct { +} tm; +struct tm *localtime(struct tm *tm); int strcmp(const char*, const char*); extern void foo(char *e); From 6d6f95fc0e25a4e0e0b2ee83b8c60e03fd45674e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0?= Date: Sat, 28 Sep 2024 17:20:00 +0200 Subject: [PATCH 02/45] [clang-tidy] add times to clang-tidy add `ctime` and `localtime` to unsafe functions check function --- clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp index 604a7cac0e4903..f058e5ae40680f 100644 --- a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp @@ -50,6 +50,8 @@ static StringRef getReplacementFor(StringRef FunctionName, StringRef AnnexKReplacementFunction = StringSwitch(FunctionName) .Cases("asctime", "asctime_r", "asctime_s") +.Cases("ctime", "ctime_r") +.Cases("localtime", "localtime_r") .Case("gets", "gets_s") .Default({}); if (!AnnexKReplacementFunction.empty()) From f60bbe61c02f91f287c5e8024ce03e137685ffee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0?= Date: Thu, 26 Dec 2024 08:30:17 +0500 Subject: [PATCH 03/45] [clang-tidy] add `ctime` and `localtime` to `clang-tidy` add changes to release notes --- clang-tools-extra/docs/ReleaseNotes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index fabd0cc78ac6
[clang] [clang] add llvm abi support (PR #121123)
https://github.com/RossComputerGuy created https://github.com/llvm/llvm-project/pull/121123 This PR makes it possible to use the LLVM ABI which uses LLVM libc. >From 058c4d297822cbde97641eb9c35d78d5742b96f2 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Wed, 25 Dec 2024 14:38:30 -0800 Subject: [PATCH] [clang] add llvm abi support --- clang/lib/Driver/Driver.cpp | 2 +- clang/lib/Driver/ToolChains/Gnu.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index dc84c1b9d1cc4e..98b8e6e97419c6 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -1531,7 +1531,7 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { // Check if the environment version is valid except wasm case. llvm::Triple Triple = TC.getTriple(); - if (!Triple.isWasm()) { + if (!Triple.isWasm() && Triple.getEnvironment() != llvm::Triple::LLVM) { StringRef TripleVersionName = Triple.getEnvironmentVersionString(); StringRef TripleObjectFormat = Triple.getObjectFormatTypeName(Triple.getObjectFormat()); diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index 8397f1121ec2ce..2c9539ef56683c 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -464,7 +464,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, if (!Args.hasArg(options::OPT_shared)) { if (Args.hasArg(options::OPT_pg)) crt1 = "gcrt1.o"; -else if (IsPIE) +else if (IsPIE && Triple.getEnvironment() != llvm::Triple::LLVM) crt1 = "Scrt1.o"; else if (IsStaticPIE) crt1 = "rcrt1.o"; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] add llvm abi support (PR #121123)
llvmbot wrote: @llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-driver Author: Tristan Ross (RossComputerGuy) Changes This PR makes it possible to use the LLVM ABI which uses LLVM libc. --- Full diff: https://github.com/llvm/llvm-project/pull/121123.diff 2 Files Affected: - (modified) clang/lib/Driver/Driver.cpp (+1-1) - (modified) clang/lib/Driver/ToolChains/Gnu.cpp (+1-1) ``diff diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index dc84c1b9d1cc4e..98b8e6e97419c6 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -1531,7 +1531,7 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { // Check if the environment version is valid except wasm case. llvm::Triple Triple = TC.getTriple(); - if (!Triple.isWasm()) { + if (!Triple.isWasm() && Triple.getEnvironment() != llvm::Triple::LLVM) { StringRef TripleVersionName = Triple.getEnvironmentVersionString(); StringRef TripleObjectFormat = Triple.getObjectFormatTypeName(Triple.getObjectFormat()); diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index 8397f1121ec2ce..2c9539ef56683c 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -464,7 +464,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, if (!Args.hasArg(options::OPT_shared)) { if (Args.hasArg(options::OPT_pg)) crt1 = "gcrt1.o"; -else if (IsPIE) +else if (IsPIE && Triple.getEnvironment() != llvm::Triple::LLVM) crt1 = "Scrt1.o"; else if (IsStaticPIE) crt1 = "rcrt1.o"; `` https://github.com/llvm/llvm-project/pull/121123 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Prevent assignment to captured structured bindings inside immutable lambda (PR #120849)
TilakChad wrote: Thanks @cor3ntin for the review and the approval. I don't have commit access as it's my very first PR. So, could you please merge this PR for me? https://github.com/llvm/llvm-project/pull/120849 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][RISCV] Remove unneeded RISCV tuple code (PR #121024)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-s390x-linux` running on `systemz-1` while building `clang` at step 5 "ninja check 1". Full details are available at: https://lab.llvm.org/buildbot/#/builders/42/builds/2501 Here is the relevant piece of the build log for the reference ``` Step 5 (ninja check 1) failure: stage 1 checked (failure) TEST 'libFuzzer-s390x-default-Linux :: fuzzer-timeout.test' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 1: /home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/./bin/clang -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/lib/fuzzer /home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/TimeoutTest.cpp -o /home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest + /home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/./bin/clang -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/lib/fuzzer /home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/TimeoutTest.cpp -o /home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest RUN: at line 2: /home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/./bin/clang -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/lib/fuzzer /home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/TimeoutEmptyTest.cpp -o /home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutEmptyTest + /home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/./bin/clang -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/lib/fuzzer /home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/TimeoutEmptyTest.cpp -o /home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutEmptyTest RUN: at line 3: not /home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest -timeout=1 2>&1 | FileCheck /home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test --check-prefix=TimeoutTest + not /home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest -timeout=1 + FileCheck /home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test --check-prefix=TimeoutTest /home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test:7:14: error: TimeoutTest: expected string not found in input TimeoutTest: #0 ^ :21:44: note: scanning from here ==1891473== ERROR: libFuzzer: timeout after 1 seconds ^ :26:104: note: possible intended match here AddressSanitizer: CHECK failed: asan_report.cpp:199 "((current_error_.kind)) == ((kErrorKindInvalid))" (0x1, 0x0) (tid=1891473) ^ Input file: Check file: /home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test -dump-input=help explains the following input dump. Input was: << . . . 16: MS: 3 CrossOver-InsertByte-CrossOver-; base unit: adc83b19e793491b1c6ea0fd8b46cd9f32e592fc 17: 0x48,0x69,0x21, 18: Hi! 19: artifact_prefix='./'; Test unit written to ./timeout-c0a0ad26a634840c67a210fefdda76577b03a111 20: Base64: SGkh 21: ==1891473== ERROR: libFuzzer: timeout after 1 seconds check:7'0X~~ error: no match found 22: AddressSanitizer:DEADLYSIGNAL check:7'0 ~~ 23: = check:7'0 ~~~
[clang] 8e7f1be - [clang][RISCV] Remove unneeded RISCV tuple code (#121024)
Author: Brandon Wu Date: 2024-12-25T22:48:54+08:00 New Revision: 8e7f1bee84ff9421f7a4b57abd1feff6b5680e1a URL: https://github.com/llvm/llvm-project/commit/8e7f1bee84ff9421f7a4b57abd1feff6b5680e1a DIFF: https://github.com/llvm/llvm-project/commit/8e7f1bee84ff9421f7a4b57abd1feff6b5680e1a.diff LOG: [clang][RISCV] Remove unneeded RISCV tuple code (#121024) These code are no longer needed because we've modeled tuple type using target extension type rather than structure of scalable vectors. Added: Modified: clang/lib/CodeGen/CGCall.cpp clang/lib/CodeGen/Targets/RISCV.cpp Removed: diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 50b9dfbbab083a..f139c30f3dfd44 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -3235,22 +3235,6 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI, llvm::StructType *STy = dyn_cast(ArgI.getCoerceToType()); - if (ArgI.isDirect() && !ArgI.getCanBeFlattened() && STy && - STy->getNumElements() > 1) { -[[maybe_unused]] llvm::TypeSize StructSize = -CGM.getDataLayout().getTypeAllocSize(STy); -[[maybe_unused]] llvm::TypeSize PtrElementSize = -CGM.getDataLayout().getTypeAllocSize(ConvertTypeForMem(Ty)); -if (STy->containsHomogeneousScalableVectorTypes()) { - assert(StructSize == PtrElementSize && - "Only allow non-fractional movement of structure with" - "homogeneous scalable vector type"); - - ArgVals.push_back(ParamValue::forDirect(AI)); - break; -} - } - Address Alloca = CreateMemTemp(Ty, getContext().getDeclAlign(Arg), Arg->getName()); @@ -5414,21 +5398,6 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, llvm::StructType *STy = dyn_cast(ArgInfo.getCoerceToType()); - if (STy && ArgInfo.isDirect() && !ArgInfo.getCanBeFlattened()) { -llvm::Type *SrcTy = ConvertTypeForMem(I->Ty); -[[maybe_unused]] llvm::TypeSize SrcTypeSize = -CGM.getDataLayout().getTypeAllocSize(SrcTy); -[[maybe_unused]] llvm::TypeSize DstTypeSize = -CGM.getDataLayout().getTypeAllocSize(STy); -if (STy->containsHomogeneousScalableVectorTypes()) { - assert(SrcTypeSize == DstTypeSize && - "Only allow non-fractional movement of structure with " - "homogeneous scalable vector type"); - - IRCallArgs[FirstIRArg] = I->getKnownRValue().getScalarVal(); - break; -} - } // FIXME: Avoid the conversion through memory if possible. Address Src = Address::invalid(); diff --git a/clang/lib/CodeGen/Targets/RISCV.cpp b/clang/lib/CodeGen/Targets/RISCV.cpp index b04e436c665f52..873e696e1328f9 100644 --- a/clang/lib/CodeGen/Targets/RISCV.cpp +++ b/clang/lib/CodeGen/Targets/RISCV.cpp @@ -495,13 +495,7 @@ ABIArgInfo RISCVABIInfo::classifyArgumentType(QualType Ty, bool IsFixed, return getNaturalAlignIndirect(Ty, /*ByVal=*/false); } -ABIArgInfo Info = ABIArgInfo::getDirect(); - -// If it is tuple type, it can't be flattened. -if (llvm::StructType *STy = dyn_cast(CGT.ConvertType(Ty))) - Info.setCanBeFlattened(!STy->containsHomogeneousScalableVectorTypes()); - -return Info; +return ABIArgInfo::getDirect(); } if (const VectorType *VT = Ty->getAs()) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][RISCV] Remove unneeded RISCV tuple code (PR #121024)
https://github.com/4vtomat closed https://github.com/llvm/llvm-project/pull/121024 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)
@@ -11077,6 +11077,221 @@ TEST_F(FormatTest, WrapsTemplateDeclarationsWithComments) { Style); } +TEST_F(FormatTest, BreakBeforeTemplateClose) { HazardyKnusperkeks wrote: Sorry missed that, didn't look for the lambda case. https://github.com/llvm/llvm-project/pull/118046 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Clang] restrict use of attribute names reserved by the C++ standard (PR #106036)
https://github.com/a-tarasyuk converted_to_draft https://github.com/llvm/llvm-project/pull/106036 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Clang] restrict use of attribute names reserved by the C++ standard (PR #106036)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/106036 >From d4b07c7ff65ca64a5a434818ce09ecd289401340 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Tue, 10 Sep 2024 02:35:43 +0300 Subject: [PATCH 1/3] [Clang] restrict use of attribute names reserved by the C++ standard --- clang/docs/ReleaseNotes.rst | 2 ++ .../include/clang/Basic/AttributeCommonInfo.h | 2 +- clang/include/clang/Basic/CMakeLists.txt | 5 +++ clang/include/clang/Basic/DiagnosticGroups.td | 1 + .../include/clang/Basic/DiagnosticLexKinds.td | 2 ++ clang/include/clang/Lex/Preprocessor.h| 10 +++--- clang/include/clang/Sema/CMakeLists.txt | 5 --- clang/lib/Lex/PPDirectives.cpp| 26 +- .../Preprocessor/macro-reserved-attrs1.cpp| 34 +++ .../Preprocessor/macro-reserved-attrs2.cpp| 34 +++ .../gn/secondary/clang/lib/Basic/BUILD.gn | 5 +-- .../gn/secondary/clang/lib/Sema/BUILD.gn | 2 +- .../llvm-project-overlay/clang/BUILD.bazel| 9 +++-- 13 files changed, 115 insertions(+), 22 deletions(-) create mode 100644 clang/test/Preprocessor/macro-reserved-attrs1.cpp create mode 100644 clang/test/Preprocessor/macro-reserved-attrs2.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 250821a9f9c45c..eecf5de3775f21 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -298,6 +298,8 @@ Improvements to Clang's diagnostics - Clang now warns for u8 character literals used in C23 with ``-Wpre-c23-compat`` instead of ``-Wpre-c++17-compat``. +- Clang now diagnoses the use of attribute names reserved by the C++ standard. (#GH92196). + Improvements to Clang's time-trace -- diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h b/clang/include/clang/Basic/AttributeCommonInfo.h index 5f024b4b5fd782..15e2685e049d9c 100644 --- a/clang/include/clang/Basic/AttributeCommonInfo.h +++ b/clang/include/clang/Basic/AttributeCommonInfo.h @@ -61,7 +61,7 @@ class AttributeCommonInfo { }; enum Kind { #define PARSED_ATTR(NAME) AT_##NAME, -#include "clang/Sema/AttrParsedAttrList.inc" +#include "clang/Basic/AttrParsedAttrList.inc" #undef PARSED_ATTR NoSemaHandlerAttribute, IgnoredAttribute, diff --git a/clang/include/clang/Basic/CMakeLists.txt b/clang/include/clang/Basic/CMakeLists.txt index f069f4fc118f27..bcc34e86385926 100644 --- a/clang/include/clang/Basic/CMakeLists.txt +++ b/clang/include/clang/Basic/CMakeLists.txt @@ -31,6 +31,11 @@ clang_tablegen(AttrList.inc -gen-clang-attr-list SOURCE Attr.td TARGET ClangAttrList) +clang_tablegen(AttrParsedAttrList.inc -gen-clang-attr-parsed-attr-list + -I ${CMAKE_CURRENT_SOURCE_DIR}/../../ + SOURCE Attr.td + TARGET ClangAttrParsedAttrList) + clang_tablegen(AttrSubMatchRulesList.inc -gen-clang-attr-subject-match-rule-list -I ${CMAKE_CURRENT_SOURCE_DIR}/../../ SOURCE Attr.td diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 116ce7a04f66f7..f04afce2da5a8c 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -751,6 +751,7 @@ def AmbiguousMacro : DiagGroup<"ambiguous-macro">; def KeywordAsMacro : DiagGroup<"keyword-macro">; def ReservedIdAsMacro : DiagGroup<"reserved-macro-identifier">; def ReservedIdAsMacroAlias : DiagGroup<"reserved-id-macro", [ReservedIdAsMacro]>; +def ReservedAttributeIdentifier : DiagGroup<"reserved-attribute-identifier">; def RestrictExpansionMacro : DiagGroup<"restrict-expansion">; def FinalMacro : DiagGroup<"final-macro">; diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td index fc14bb6aa21651..7e1964b6284c83 100644 --- a/clang/include/clang/Basic/DiagnosticLexKinds.td +++ b/clang/include/clang/Basic/DiagnosticLexKinds.td @@ -407,6 +407,8 @@ def warn_pp_macro_hides_keyword : Extension< def warn_pp_macro_is_reserved_id : Warning< "macro name is a reserved identifier">, DefaultIgnore, InGroup; +def warn_pp_macro_is_reserved_attribute_id : Warning< + "%0 is a reserved attribute identifier">, InGroup; def warn_pp_objc_macro_redef_ignored : Warning< "ignoring redefinition of Objective-C qualifier macro">, InGroup>; diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index 1307659e27d137..1e1d5ce0de48dc 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -2286,6 +2286,11 @@ class Preprocessor { } } + /// Determine whether the next preprocessor token to be + /// lexed is a '('. If so, consume the token and return true, if not, this + /// method should have no observable side-effect on the lexed tokens. + bool isNextPPTokenLParen(); + private: /// Identifiers used for SEH handling in Borland. These are on
[clang] [llvm] [Clang] restrict use of attribute names reserved by the C++ standard (PR #106036)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/106036 >From d4b07c7ff65ca64a5a434818ce09ecd289401340 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Tue, 10 Sep 2024 02:35:43 +0300 Subject: [PATCH 1/2] [Clang] restrict use of attribute names reserved by the C++ standard --- clang/docs/ReleaseNotes.rst | 2 ++ .../include/clang/Basic/AttributeCommonInfo.h | 2 +- clang/include/clang/Basic/CMakeLists.txt | 5 +++ clang/include/clang/Basic/DiagnosticGroups.td | 1 + .../include/clang/Basic/DiagnosticLexKinds.td | 2 ++ clang/include/clang/Lex/Preprocessor.h| 10 +++--- clang/include/clang/Sema/CMakeLists.txt | 5 --- clang/lib/Lex/PPDirectives.cpp| 26 +- .../Preprocessor/macro-reserved-attrs1.cpp| 34 +++ .../Preprocessor/macro-reserved-attrs2.cpp| 34 +++ .../gn/secondary/clang/lib/Basic/BUILD.gn | 5 +-- .../gn/secondary/clang/lib/Sema/BUILD.gn | 2 +- .../llvm-project-overlay/clang/BUILD.bazel| 9 +++-- 13 files changed, 115 insertions(+), 22 deletions(-) create mode 100644 clang/test/Preprocessor/macro-reserved-attrs1.cpp create mode 100644 clang/test/Preprocessor/macro-reserved-attrs2.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 250821a9f9c45c..eecf5de3775f21 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -298,6 +298,8 @@ Improvements to Clang's diagnostics - Clang now warns for u8 character literals used in C23 with ``-Wpre-c23-compat`` instead of ``-Wpre-c++17-compat``. +- Clang now diagnoses the use of attribute names reserved by the C++ standard. (#GH92196). + Improvements to Clang's time-trace -- diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h b/clang/include/clang/Basic/AttributeCommonInfo.h index 5f024b4b5fd782..15e2685e049d9c 100644 --- a/clang/include/clang/Basic/AttributeCommonInfo.h +++ b/clang/include/clang/Basic/AttributeCommonInfo.h @@ -61,7 +61,7 @@ class AttributeCommonInfo { }; enum Kind { #define PARSED_ATTR(NAME) AT_##NAME, -#include "clang/Sema/AttrParsedAttrList.inc" +#include "clang/Basic/AttrParsedAttrList.inc" #undef PARSED_ATTR NoSemaHandlerAttribute, IgnoredAttribute, diff --git a/clang/include/clang/Basic/CMakeLists.txt b/clang/include/clang/Basic/CMakeLists.txt index f069f4fc118f27..bcc34e86385926 100644 --- a/clang/include/clang/Basic/CMakeLists.txt +++ b/clang/include/clang/Basic/CMakeLists.txt @@ -31,6 +31,11 @@ clang_tablegen(AttrList.inc -gen-clang-attr-list SOURCE Attr.td TARGET ClangAttrList) +clang_tablegen(AttrParsedAttrList.inc -gen-clang-attr-parsed-attr-list + -I ${CMAKE_CURRENT_SOURCE_DIR}/../../ + SOURCE Attr.td + TARGET ClangAttrParsedAttrList) + clang_tablegen(AttrSubMatchRulesList.inc -gen-clang-attr-subject-match-rule-list -I ${CMAKE_CURRENT_SOURCE_DIR}/../../ SOURCE Attr.td diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 116ce7a04f66f7..f04afce2da5a8c 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -751,6 +751,7 @@ def AmbiguousMacro : DiagGroup<"ambiguous-macro">; def KeywordAsMacro : DiagGroup<"keyword-macro">; def ReservedIdAsMacro : DiagGroup<"reserved-macro-identifier">; def ReservedIdAsMacroAlias : DiagGroup<"reserved-id-macro", [ReservedIdAsMacro]>; +def ReservedAttributeIdentifier : DiagGroup<"reserved-attribute-identifier">; def RestrictExpansionMacro : DiagGroup<"restrict-expansion">; def FinalMacro : DiagGroup<"final-macro">; diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td index fc14bb6aa21651..7e1964b6284c83 100644 --- a/clang/include/clang/Basic/DiagnosticLexKinds.td +++ b/clang/include/clang/Basic/DiagnosticLexKinds.td @@ -407,6 +407,8 @@ def warn_pp_macro_hides_keyword : Extension< def warn_pp_macro_is_reserved_id : Warning< "macro name is a reserved identifier">, DefaultIgnore, InGroup; +def warn_pp_macro_is_reserved_attribute_id : Warning< + "%0 is a reserved attribute identifier">, InGroup; def warn_pp_objc_macro_redef_ignored : Warning< "ignoring redefinition of Objective-C qualifier macro">, InGroup>; diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index 1307659e27d137..1e1d5ce0de48dc 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -2286,6 +2286,11 @@ class Preprocessor { } } + /// Determine whether the next preprocessor token to be + /// lexed is a '('. If so, consume the token and return true, if not, this + /// method should have no observable side-effect on the lexed tokens. + bool isNextPPTokenLParen(); + private: /// Identifiers used for SEH handling in Borland. These are on