From 61c8b7159a740d43a6a0fa52756eb479e1a9c1c3 Mon Sep 17 00:00:00 2001 From: Vipul Cariappa Date: Fri, 27 Sep 2024 12:33:32 +0530 Subject: [clang] return first Decl for CanonicalDecl in TranslationUnitDecl (#110101) Return the first `Decl` when using `TranslationUnitDecl::getCanonicalDecl` --- clang/unittests/Interpreter/InterpreterTest.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'clang/unittests/Interpreter/InterpreterTest.cpp') diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp b/clang/unittests/Interpreter/InterpreterTest.cpp index a2e960f..30b051e 100644 --- a/clang/unittests/Interpreter/InterpreterTest.cpp +++ b/clang/unittests/Interpreter/InterpreterTest.cpp @@ -381,4 +381,26 @@ TEST_F(InterpreterTest, Value) { EXPECT_TRUE(V9.isManuallyAlloc()); } +TEST_F(InterpreterTest, TranslationUnit_CanonicalDecl) { + std::vector Args; + std::unique_ptr Interp = createInterpreter(Args); + + Sema &sema = Interp->getCompilerInstance()->getSema(); + + llvm::cantFail(Interp->ParseAndExecute("int x = 42;")); + + TranslationUnitDecl *TU = + sema.getASTContext().getTranslationUnitDecl()->getCanonicalDecl(); + + llvm::cantFail(Interp->ParseAndExecute("long y = 84;")); + + EXPECT_EQ(TU, + sema.getASTContext().getTranslationUnitDecl()->getCanonicalDecl()); + + llvm::cantFail(Interp->ParseAndExecute("char z = 'z';")); + + EXPECT_EQ(TU, + sema.getASTContext().getTranslationUnitDecl()->getCanonicalDecl()); +} + } // end anonymous namespace -- cgit v1.1