From 18fa3aca318652d76b56f04c969ca19472d1ba9d Mon Sep 17 00:00:00 2001 From: Christoph Hart Date: Sun, 13 Oct 2024 13:07:30 +0200 Subject: [PATCH] - fix SNEX compiler not detecting illegal outer class member access --- currentGitHash.txt | 2 +- hi_backend/backend/currentGit.h | 2 +- .../snex_jit/snex_jit_OperationsSymbols.cpp | 23 ++++++++++++ .../test_files/struct/outer_member_access.h | 35 +++++++++++++++++++ 4 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 tools/snex_playground/test_files/struct/outer_member_access.h diff --git a/currentGitHash.txt b/currentGitHash.txt index 2cb7b4573f..c5284f81e0 100644 --- a/currentGitHash.txt +++ b/currentGitHash.txt @@ -1 +1 @@ -c74524c48743ccc455d802694a731daa94a1bf8e +00822079687481f8979f0fe7299029f3e988160b diff --git a/hi_backend/backend/currentGit.h b/hi_backend/backend/currentGit.h index 603df84b97..0832a64a33 100644 --- a/hi_backend/backend/currentGit.h +++ b/hi_backend/backend/currentGit.h @@ -1 +1 @@ -#define PREVIOUS_HISE_COMMIT "c74524c48743ccc455d802694a731daa94a1bf8e" +#define PREVIOUS_HISE_COMMIT "00822079687481f8979f0fe7299029f3e988160b" diff --git a/hi_snex/snex_jit/snex_jit_OperationsSymbols.cpp b/hi_snex/snex_jit/snex_jit_OperationsSymbols.cpp index 5a8cd5ff9a..7f6083ffe5 100644 --- a/hi_snex/snex_jit/snex_jit_OperationsSymbols.cpp +++ b/hi_snex/snex_jit/snex_jit_OperationsSymbols.cpp @@ -645,6 +645,29 @@ void Operations::ThisPointer::process(BaseCompiler* compiler, BaseScope* scope) { processBaseWithoutChildren(compiler, scope); + COMPILER_PASS(BaseCompiler::ResolvingSymbols) + { + auto cScope = scope->getParentScopeOfType(); + + if(auto currentClass = dynamic_cast(cScope->typePtr.get())) + { + auto thisType = dynamic_cast(type.get()); + + if(thisType != currentClass) + { + // Apparently we need to allow different template parameters to go through + // here so we check the namespaced identifier + auto differentClass = thisType->id != currentClass->id; + + if(differentClass) + location.throwError("Can't access outer member from inner class"); + } + } + + + + } + #if SNEX_ASMJIT_BACKEND COMPILER_PASS(BaseCompiler::CodeGeneration) { diff --git a/tools/snex_playground/test_files/struct/outer_member_access.h b/tools/snex_playground/test_files/struct/outer_member_access.h new file mode 100644 index 0000000000..329c5e1657 --- /dev/null +++ b/tools/snex_playground/test_files/struct/outer_member_access.h @@ -0,0 +1,35 @@ +/* +BEGIN_TEST_DATA + f: main + ret: int + args: int + input: 12 + output: 12 + error: "Line 21(11): Can't access outer member from inner class" + filename: "struct/outer_member_access" +END_TEST_DATA +*/ + +struct Outer +{ + struct Inner + { + int x = 9; + + int getV() + { + return v; + } + }; + + Inner data; + + int v = 12; +}; + +int main(int input) +{ + Outer obj; + return obj.data.getV(); +} +