Skip to content

Commit

Permalink
Fix compilation and plugin tests for v1.30
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanEngelen committed Jul 31, 2023
1 parent f5462a2 commit 9dc0f3a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
10 changes: 9 additions & 1 deletion driver/plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/DynamicLibrary.h"

#if LDC_LLVM_VER >= 1400
#include "llvm/ADT/SmallVector.h"
#include "llvm/Passes/PassPlugin.h"
#include "llvm/Support/Error.h"

#include "driver/cl_options.h"
#endif

namespace {
namespace cl = llvm::cl;

Expand Down Expand Up @@ -106,7 +114,7 @@ void loadLLVMPluginNewPM(const std::string &filename) {

void loadLLVMPlugin(const std::string &filename) {
#if LDC_LLVM_VER >= 1400
if (opts::isUsingLegacyPassManager())
if (true /*opts::isUsingLegacyPassManager()*/)
loadLLVMPluginLegacyPM(filename);
else
loadLLVMPluginNewPM(filename);
Expand Down
1 change: 0 additions & 1 deletion tests/plugins/basic_sema_plugin.d
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
//--- plugin.d
import dmd.dmodule : Module;
import dmd.errors;
import dmd.location;

extern(C) void runSemanticAnalysis(Module m) {
if (m.md) {
Expand Down
28 changes: 21 additions & 7 deletions tests/plugins/visitor_example.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
//--- plugin.d
import dmd.dmodule;
import dmd.errors;
import dmd.location;
import dmd.visitor;
import dmd.declaration;
import dmd.dsymbol;
Expand All @@ -20,13 +19,28 @@ extern(C++) class MyVisitor : SemanticTimeTransitiveVisitor {
alias visit = SemanticTimeTransitiveVisitor.visit;

override void visit(VarDeclaration vd) {
if (vd.aliasTuple) {
vd.aliasTuple.foreachVar((s) {
auto vardecl = s.isVarDeclaration();
if (vardecl && vardecl.type.needsDestruction()) {
warning(vardecl.loc, "It works!");
if (vd.aliassym) {
TupleDeclaration tup = vd.aliassym.isTupleDeclaration();
visit(tup);
}
}

override void visit(TupleDeclaration vd) {
import dmd.dtemplate : isDsymbol;
import dmd.root.rootobject;
import dmd.expression;

for (size_t i = 0; i < vd.objects.dim; i++) {
auto o = (*vd.objects)[i];
if (o.dyncast() == DYNCAST.expression) {
Expression e = cast(Expression) o;
if (DsymbolExp ve = e.isDsymbolExp()) {
auto vardecl = ve.s.isVarDeclaration();
if (vardecl && vardecl.type.needsDestruction()) {
warning(vardecl.loc, "It works!");
}
}
});
}
}
}
}
Expand Down

0 comments on commit 9dc0f3a

Please sign in to comment.