forked from GPUOpen-Drivers/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged master:340c376b87c into amd-gfx:e4f18c6a7d7
Local branch amd-gfx e4f18c6 Merged master:2d3b8cc83fe into amd-gfx:73e365b16db Remote branch master 340c376 [lldb] Fix a CMake warning typo. NFC.
- Loading branch information
Showing
60 changed files
with
35,413 additions
and
269 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
//===- unittest/AST/HasSideEffectsTest.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 "clang/AST/RecursiveASTVisitor.h" | ||
#include "clang/AST/ASTConsumer.h" | ||
#include "clang/AST/ASTContext.h" | ||
#include "clang/AST/Attr.h" | ||
#include "clang/Frontend/FrontendAction.h" | ||
#include "clang/Tooling/Tooling.h" | ||
#include "llvm/ADT/FunctionExtras.h" | ||
#include "llvm/ADT/STLExtras.h" | ||
#include "gmock/gmock.h" | ||
#include "gtest/gtest.h" | ||
#include <cassert> | ||
|
||
using namespace clang; | ||
|
||
namespace { | ||
class ProcessASTAction : public clang::ASTFrontendAction { | ||
public: | ||
ProcessASTAction(llvm::unique_function<void(clang::ASTContext &)> Process) | ||
: Process(std::move(Process)) { | ||
assert(this->Process); | ||
} | ||
|
||
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, | ||
StringRef InFile) { | ||
class Consumer : public ASTConsumer { | ||
public: | ||
Consumer(llvm::function_ref<void(ASTContext &CTx)> Process) | ||
: Process(Process) {} | ||
|
||
void HandleTranslationUnit(ASTContext &Ctx) override { Process(Ctx); } | ||
|
||
private: | ||
llvm::function_ref<void(ASTContext &CTx)> Process; | ||
}; | ||
|
||
return std::make_unique<Consumer>(Process); | ||
} | ||
|
||
private: | ||
llvm::unique_function<void(clang::ASTContext &)> Process; | ||
}; | ||
|
||
class RunHasSideEffects | ||
: public RecursiveASTVisitor<RunHasSideEffects> { | ||
public: | ||
RunHasSideEffects(ASTContext& Ctx) | ||
: Ctx(Ctx) {} | ||
|
||
bool VisitLambdaExpr(LambdaExpr *LE) { | ||
LE->HasSideEffects(Ctx); | ||
return true; | ||
} | ||
|
||
ASTContext& Ctx; | ||
}; | ||
} // namespace | ||
|
||
TEST(HasSideEffectsTest, All) { | ||
llvm::StringRef Code = R"cpp( | ||
void Test() { | ||
int msize = 4; | ||
float arr[msize]; | ||
[&arr] {}; | ||
} | ||
)cpp"; | ||
|
||
ASSERT_NO_FATAL_FAILURE( | ||
clang::tooling::runToolOnCode( | ||
std::make_unique<ProcessASTAction>( | ||
[&](clang::ASTContext &Ctx) { | ||
RunHasSideEffects Visitor(Ctx); | ||
Visitor.TraverseAST(Ctx); | ||
} | ||
), | ||
Code) | ||
); | ||
|
||
} |
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
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
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
Binary file not shown.
Oops, something went wrong.