File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -133,6 +133,10 @@ class TranslationUnitDecl : public Decl,
133133 static TranslationUnitDecl *castFromDeclContext (const DeclContext *DC) {
134134 return static_cast <TranslationUnitDecl *>(const_cast <DeclContext*>(DC));
135135 }
136+
137+ // / Retrieves the canonical declaration of this translation unit.
138+ TranslationUnitDecl *getCanonicalDecl () override { return getFirstDecl (); }
139+ const TranslationUnitDecl *getCanonicalDecl () const { return getFirstDecl (); }
136140};
137141
138142// / Represents a `#pragma comment` line. Always a child of
Original file line number Diff line number Diff line change @@ -381,4 +381,26 @@ TEST_F(InterpreterTest, Value) {
381381 EXPECT_TRUE (V9.isManuallyAlloc ());
382382}
383383
384+ TEST_F (InterpreterTest, TranslationUnit_CanonicalDecl) {
385+ std::vector<const char *> Args;
386+ std::unique_ptr<Interpreter> Interp = createInterpreter (Args);
387+
388+ Sema &sema = Interp->getCompilerInstance ()->getSema ();
389+
390+ llvm::cantFail (Interp->ParseAndExecute (" int x = 42;" ));
391+
392+ TranslationUnitDecl *TU =
393+ sema.getASTContext ().getTranslationUnitDecl ()->getCanonicalDecl ();
394+
395+ llvm::cantFail (Interp->ParseAndExecute (" long y = 84;" ));
396+
397+ EXPECT_EQ (TU,
398+ sema.getASTContext ().getTranslationUnitDecl ()->getCanonicalDecl ());
399+
400+ llvm::cantFail (Interp->ParseAndExecute (" char z = 'z';" ));
401+
402+ EXPECT_EQ (TU,
403+ sema.getASTContext ().getTranslationUnitDecl ()->getCanonicalDecl ());
404+ }
405+
384406} // end anonymous namespace
You can’t perform that action at this time.
0 commit comments