Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[clang-tidy] add ctime and localtime to clang-tidy #110366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 59 commits into
base: main
Choose a base branch
from

Conversation

zimirza
Copy link
Contributor

@zimirza zimirza commented Sep 28, 2024

Closes #107445

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:static analyzer labels Sep 28, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 28, 2024

@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clang-static-analyzer-1

Author: Зишан Мирза (zimirza)

Changes

Closes #107445


Full diff: https://github.com/llvm/llvm-project/pull/110366.diff

5 Files Affected:

  • (modified) clang/docs/tools/clang-formatted-files.txt (+8)
  • (modified) clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp (+4)
  • (modified) clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc (+4)
  • (modified) clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc (+6)
  • (modified) clang/test/Analysis/cert/env34-c.c (+8-1)
diff --git a/clang/docs/tools/clang-formatted-files.txt b/clang/docs/tools/clang-formatted-files.txt
index 67ff085144f4de..5223ca82a5b575 100644
--- a/clang/docs/tools/clang-formatted-files.txt
+++ b/clang/docs/tools/clang-formatted-files.txt
@@ -3058,6 +3058,14 @@ libc/src/threads/linux/thrd_join.cpp
 libc/src/threads/linux/Thread.h
 libc/src/time/asctime.cpp
 libc/src/time/asctime.h
+libc/src/time/ctime.cpp
+libc/src/time/ctime.h
+libc/src/time/ctime_r.cpp
+libc/src/time/ctime_r.h
+libc/src/time/localtime.cpp
+libc/src/time/localtime.h
+libc/src/time/localtime_r.cpp
+libc/src/time/localtime_r.h
 libc/src/time/asctime_r.cpp
 libc/src/time/asctime_r.h
 libc/src/time/gmtime.cpp
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, <iso646.h>)
 SYMBOL(and_eq, None, <iso646.h>)
 SYMBOL(asctime, None, <time.h>)
 SYMBOL(asctime_s, None, <time.h>)
+SYMBOL(ctime, None, <time.h>)
+SYMBOL(ctime_s, None, <time.h>)
+SYMBOL(localtime, None, <time.h>)
+SYMBOL(localtime_s, None, <time.h>)
 SYMBOL(asin, None, <math.h>)
 SYMBOL(asinf, None, <math.h>)
 SYMBOL(asinh, None, <math.h>)
diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
index b46bd2e4d7a4b5..8e3471e2fc5729 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
@@ -617,6 +617,12 @@ SYMBOL(as_writable_bytes, std::, <span>)
 SYMBOL(asctime, std::, <ctime>)
 SYMBOL(asctime, None, <ctime>)
 SYMBOL(asctime, None, <time.h>)
+SYMBOL(ctime, std::, <time.h>)
+SYMBOL(ctime, None, <ctime>)
+SYMBOL(ctime, None, <time.h>)
+SYMBOL(localtime, std::, <ctime>)
+SYMBOL(localtime, None, <ctime>)
+SYMBOL(localtime, None, <time.h>)
 SYMBOL(asin, std::, <cmath>)
 SYMBOL(asin, None, <cmath>)
 SYMBOL(asin, None, <math.h>)
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);

@llvmbot
Copy link
Member

llvmbot commented Sep 28, 2024

@llvm/pr-subscribers-clang

Author: Зишан Мирза (zimirza)

Changes

Closes #107445


Full diff: https://github.com/llvm/llvm-project/pull/110366.diff

5 Files Affected:

  • (modified) clang/docs/tools/clang-formatted-files.txt (+8)
  • (modified) clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp (+4)
  • (modified) clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc (+4)
  • (modified) clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc (+6)
  • (modified) clang/test/Analysis/cert/env34-c.c (+8-1)
diff --git a/clang/docs/tools/clang-formatted-files.txt b/clang/docs/tools/clang-formatted-files.txt
index 67ff085144f4de..5223ca82a5b575 100644
--- a/clang/docs/tools/clang-formatted-files.txt
+++ b/clang/docs/tools/clang-formatted-files.txt
@@ -3058,6 +3058,14 @@ libc/src/threads/linux/thrd_join.cpp
 libc/src/threads/linux/Thread.h
 libc/src/time/asctime.cpp
 libc/src/time/asctime.h
+libc/src/time/ctime.cpp
+libc/src/time/ctime.h
+libc/src/time/ctime_r.cpp
+libc/src/time/ctime_r.h
+libc/src/time/localtime.cpp
+libc/src/time/localtime.h
+libc/src/time/localtime_r.cpp
+libc/src/time/localtime_r.h
 libc/src/time/asctime_r.cpp
 libc/src/time/asctime_r.h
 libc/src/time/gmtime.cpp
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, <iso646.h>)
 SYMBOL(and_eq, None, <iso646.h>)
 SYMBOL(asctime, None, <time.h>)
 SYMBOL(asctime_s, None, <time.h>)
+SYMBOL(ctime, None, <time.h>)
+SYMBOL(ctime_s, None, <time.h>)
+SYMBOL(localtime, None, <time.h>)
+SYMBOL(localtime_s, None, <time.h>)
 SYMBOL(asin, None, <math.h>)
 SYMBOL(asinf, None, <math.h>)
 SYMBOL(asinh, None, <math.h>)
diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
index b46bd2e4d7a4b5..8e3471e2fc5729 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
@@ -617,6 +617,12 @@ SYMBOL(as_writable_bytes, std::, <span>)
 SYMBOL(asctime, std::, <ctime>)
 SYMBOL(asctime, None, <ctime>)
 SYMBOL(asctime, None, <time.h>)
+SYMBOL(ctime, std::, <time.h>)
+SYMBOL(ctime, None, <ctime>)
+SYMBOL(ctime, None, <time.h>)
+SYMBOL(localtime, std::, <ctime>)
+SYMBOL(localtime, None, <ctime>)
+SYMBOL(localtime, None, <time.h>)
 SYMBOL(asin, std::, <cmath>)
 SYMBOL(asin, None, <cmath>)
 SYMBOL(asin, None, <math.h>)
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);

@EugeneZelenko
Copy link
Contributor

Please mention changes in Release Notes.

@zimirza
Copy link
Contributor Author

zimirza commented Sep 30, 2024

Sure, I can add the changes to the release notes. I noticed that tests did not work as expected. I can make this pull request a draft, since I need to figure out why tests did not work.

@zimirza zimirza force-pushed the add_time_to_clang_tidy branch from 9983c6e to 5deca5d Compare September 30, 2024 14:37
@zimirza zimirza marked this pull request as draft September 30, 2024 14:37
@zimirza
Copy link
Contributor Author

zimirza commented Sep 30, 2024

This pull request should not be merged before #110363.

Copy link

github-actions bot commented Sep 30, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@zimirza zimirza force-pushed the add_time_to_clang_tidy branch from db3832f to 298fa84 Compare December 26, 2024 03:35
@zimirza zimirza force-pushed the add_time_to_clang_tidy branch from 32517de to 892cef4 Compare January 4, 2025 11:14
Copy link
Contributor

@EugeneZelenko EugeneZelenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also rebase from main.

@zimirza zimirza force-pushed the add_time_to_clang_tidy branch from e6ac279 to 36f2968 Compare April 30, 2025 14:46
@zimirza zimirza marked this pull request as ready for review April 30, 2025 14:58
@zimirza
Copy link
Contributor Author

zimirza commented Apr 30, 2025

localtime_s was removed from #110363, and will be added to a new pull request and ctime_s has not been merged yet (#110676). It might be a good wait before merging this pull request.

@zimirza
Copy link
Contributor Author

zimirza commented May 2, 2025

localtime_s was removed from #110363, and will be added to a new pull request and ctime_s has not been merged yet (#110676). It might be a good wait before merging this pull request.

I think it is better to remove localtime_s and ctime_s from this pull request in order to keep changes small. These will be added to a new pull request when the implementations are merged.

@zimirza
Copy link
Contributor Author

zimirza commented May 2, 2025

localtime_s was removed from #110363, and will be added to a new pull request and ctime_s has not been merged yet (#110676). It might be a good wait before merging this pull request.

I think it is better to remove localtime_s and ctime_s from this pull request in order to keep changes small. These will be added to a new pull request when the implementations are merged.

localtime_s and ctime_s is currently available in a separate branch: https://github.com/zimirza/llvm-project/tree/add_time_to_clang_tidy_with_ctime_s_and_localtime_s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:static analyzer clang Clang issues not falling into any other category clang-tidy clang-tools-extra
Projects
None yet
Development

Successfully merging this pull request may close these issues.

clang-tidy: Add ctime, ctime_r, localtime, and localtime_r to clang-tidy
3 participants