Files
clang-p2996/clang/unittests/Tooling/RecursiveASTVisitorTests/BitfieldInitializer.cpp
Shivam Gupta 897cc8a7d7 [RecursiveASTVisitor] Fix RecursiveASTVisitor (RAV) fails to visit the initializer of a bitfield (#69557)
The problem was introduced in the commit
6b8e3c02ca
when the possibility of initialized bitfields was added, but the logic
in RecursiveASTVisitor was not updated. This PR fixed that.

This fixes https://github.com/llvm/llvm-project/issues/64916.

Patch by Scott McPeak

---------

Co-authored-by: cor3ntin <corentinjabot@gmail.com>
2023-10-26 12:39:48 +05:30

35 lines
1.0 KiB
C++

//===- 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