forked from llvm/llvm-project
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RecursiveASTVisitor] Fix RecursiveASTVisitor (RAV) fails to visit th…
…e initializer of a bitfield (llvm#69557) The problem was introduced in the commit llvm@6b8e3c0 when the possibility of initialized bitfields was added, but the logic in RecursiveASTVisitor was not updated. This PR fixed that. This fixes llvm#64916. Patch by Scott McPeak --------- Co-authored-by: cor3ntin <corentinjabot@gmail.com>
- Loading branch information
Showing
4 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
clang/unittests/Tooling/RecursiveASTVisitorTests/BitfieldInitializer.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//===- unittest/Tooling/RecursiveASTVisitorTests/BitfieldInitializer.cpp -===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "TestVisitor.h" | ||
#include <string> | ||
|
||
using namespace clang; | ||
|
||
namespace { | ||
|
||
// Check to ensure that bitfield initializers are visited. | ||
class BitfieldInitializerVisitor | ||
: public ExpectedLocationVisitor<BitfieldInitializerVisitor> { | ||
public: | ||
bool VisitIntegerLiteral(IntegerLiteral *IL) { | ||
Match(std::to_string(IL->getValue().getSExtValue()), IL->getLocation()); | ||
return true; | ||
} | ||
}; | ||
|
||
TEST(RecursiveASTVisitor, BitfieldInitializerIsVisited) { | ||
BitfieldInitializerVisitor Visitor; | ||
Visitor.ExpectMatch("123", 2, 15); | ||
EXPECT_TRUE(Visitor.runOver("struct S {\n" | ||
" int x : 8 = 123;\n" | ||
"};\n")); | ||
} | ||
|
||
} // end anonymous namespace |