From acb0b9f07e1a1308af77952780c160fbab378f77 Mon Sep 17 00:00:00 2001 From: Simon Martin Date: Sun, 26 Aug 2018 19:46:36 +0200 Subject: [PATCH] Ticket #8679: Add support for C++11 thread_local and GCC's (among others) __thread extension. (#1351) --- lib/tokenize.cpp | 7 ++++++- test/testbufferoverrun.cpp | 14 ++++++++++++++ test/testtokenize.cpp | 7 +++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 0b80e1d87..847fd1624 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9024,6 +9024,7 @@ static const std::set keywords = { , "register" , "__restrict" , "__restrict__" + , "__thread" }; // Remove "inline", "register", "restrict", "override", "final", "static" and "constexpr" // "restrict" keyword @@ -9093,6 +9094,11 @@ void Tokenizer::simplifyKeyword() tok = tok->tokAt(3); Token::createMutualLinks(braceStart, braceEnd); } + + // 3) thread_local + else if (tok->str() == "thread_local") { + tok->deleteThis(); + } } } } @@ -10410,4 +10416,3 @@ bool Tokenizer::VariableMap::hasVariable(const std::string &varname) const { return mVariableId.find(varname) != mVariableId.end(); } - diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 04d8b19ca..3e5429e19 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -224,6 +224,7 @@ private: TEST_CASE(crash1); // Ticket #1587 - crash TEST_CASE(crash2); // Ticket #3034 - crash TEST_CASE(crash3); // Ticket #5426 - crash + TEST_CASE(crash4); // Ticket #8679 - crash TEST_CASE(executionPaths1); TEST_CASE(executionPaths2); @@ -3639,6 +3640,19 @@ private: "void d() { struct b *f; f = malloc(108); }"); } + void crash4() { // #8679 + check("__thread void *thread_local_var; " + "int main() { " + " thread_local_var = malloc(1337); " + " return 0; " + "}"); + + check("thread_local void *thread_local_var; " + "int main() { " + " thread_local_var = malloc(1337); " + " return 0; " + "}"); + } void executionPaths1() { check("void f(int a)\n" diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index f84f17add..4b1dfc0d0 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -4081,6 +4081,13 @@ private: ASSERT_EQUALS(out5, tokenizeAndStringify(in5)); } + { + // Ticket #8679 + const char code[] = "thread_local void *thread_local_var; " + "__thread void *thread_local_var_2;"; + ASSERT_EQUALS("void * thread_local_var ; " + "void * thread_local_var_2 ;", tokenizeAndStringify(code)); + } } /**