Skip to content

Commit

Permalink
When accessing the data pointer for an array, first decay it to a Der…
Browse files Browse the repository at this point in the history
…ived Pointer (#54335)

Fixes #54266, I've not yet
minimized something to put into a test but in any case we can add the
large test since it executes quite quickly.

This also enables IR verification with `Strong=true` when building with
assertions, this would've caught this bug much earlier.

(cherry picked from commit 9d59ecc)
  • Loading branch information
gbaraldi authored and KristofferC committed May 6, 2024
1 parent dccf8a2 commit c7bfbec
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 50 deletions.
1 change: 1 addition & 0 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2915,6 +2915,7 @@ static Value *emit_genericmemoryptr(jl_codectx_t &ctx, Value *mem, const jl_data
PointerType *PT = cast<PointerType>(mem->getType());
assert(PT == ctx.types().T_prjlvalue);
Value *addr = emit_bitcast(ctx, mem, ctx.types().T_jlgenericmemory->getPointerTo(PT->getAddressSpace()));
addr = decay_derived(ctx, addr);
addr = ctx.builder.CreateStructGEP(ctx.types().T_jlgenericmemory, addr, 1);
setName(ctx.emission_context, addr, ".data_ptr");
PointerType *PPT = cast<PointerType>(ctx.types().T_jlgenericmemory->getElementType(1));
Expand Down
87 changes: 42 additions & 45 deletions src/clangsa/GCChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,56 +795,53 @@ static bool isMutexUnlock(StringRef name) {
false;
}

#if LLVM_VERSION_MAJOR >= 13
#define endswith_lower endswith_insensitive
#endif

bool GCChecker::isGCTrackedType(QualType QT) {
return isJuliaType(
[](StringRef Name) {
if (Name.endswith_lower("jl_value_t") ||
Name.endswith_lower("jl_svec_t") ||
Name.endswith_lower("jl_sym_t") ||
Name.endswith_lower("jl_expr_t") ||
Name.endswith_lower("jl_code_info_t") ||
Name.endswith_lower("jl_array_t") ||
Name.endswith_lower("jl_genericmemory_t") ||
//Name.endswith_lower("jl_genericmemoryref_t") ||
Name.endswith_lower("jl_method_t") ||
Name.endswith_lower("jl_method_instance_t") ||
Name.endswith_lower("jl_tupletype_t") ||
Name.endswith_lower("jl_datatype_t") ||
Name.endswith_lower("jl_typemap_entry_t") ||
Name.endswith_lower("jl_typemap_level_t") ||
Name.endswith_lower("jl_typename_t") ||
Name.endswith_lower("jl_module_t") ||
Name.endswith_lower("jl_tupletype_t") ||
Name.endswith_lower("jl_gc_tracked_buffer_t") ||
Name.endswith_lower("jl_binding_t") ||
Name.endswith_lower("jl_ordereddict_t") ||
Name.endswith_lower("jl_tvar_t") ||
Name.endswith_lower("jl_typemap_t") ||
Name.endswith_lower("jl_unionall_t") ||
Name.endswith_lower("jl_methtable_t") ||
Name.endswith_lower("jl_cgval_t") ||
Name.endswith_lower("jl_codectx_t") ||
Name.endswith_lower("jl_ast_context_t") ||
Name.endswith_lower("jl_code_instance_t") ||
Name.endswith_lower("jl_excstack_t") ||
Name.endswith_lower("jl_task_t") ||
Name.endswith_lower("jl_uniontype_t") ||
Name.endswith_lower("jl_method_match_t") ||
Name.endswith_lower("jl_vararg_t") ||
Name.endswith_lower("jl_opaque_closure_t") ||
Name.endswith_lower("jl_globalref_t") ||
if (Name.ends_with_insensitive("jl_value_t") ||
Name.ends_with_insensitive("jl_svec_t") ||
Name.ends_with_insensitive("jl_sym_t") ||
Name.ends_with_insensitive("jl_expr_t") ||
Name.ends_with_insensitive("jl_code_info_t") ||
Name.ends_with_insensitive("jl_array_t") ||
Name.ends_with_insensitive("jl_genericmemory_t") ||
//Name.ends_with_insensitive("jl_genericmemoryref_t") ||
Name.ends_with_insensitive("jl_method_t") ||
Name.ends_with_insensitive("jl_method_instance_t") ||
Name.ends_with_insensitive("jl_tupletype_t") ||
Name.ends_with_insensitive("jl_datatype_t") ||
Name.ends_with_insensitive("jl_typemap_entry_t") ||
Name.ends_with_insensitive("jl_typemap_level_t") ||
Name.ends_with_insensitive("jl_typename_t") ||
Name.ends_with_insensitive("jl_module_t") ||
Name.ends_with_insensitive("jl_tupletype_t") ||
Name.ends_with_insensitive("jl_gc_tracked_buffer_t") ||
Name.ends_with_insensitive("jl_binding_t") ||
Name.ends_with_insensitive("jl_ordereddict_t") ||
Name.ends_with_insensitive("jl_tvar_t") ||
Name.ends_with_insensitive("jl_typemap_t") ||
Name.ends_with_insensitive("jl_unionall_t") ||
Name.ends_with_insensitive("jl_methtable_t") ||
Name.ends_with_insensitive("jl_cgval_t") ||
Name.ends_with_insensitive("jl_codectx_t") ||
Name.ends_with_insensitive("jl_ast_context_t") ||
Name.ends_with_insensitive("jl_code_instance_t") ||
Name.ends_with_insensitive("jl_excstack_t") ||
Name.ends_with_insensitive("jl_task_t") ||
Name.ends_with_insensitive("jl_uniontype_t") ||
Name.ends_with_insensitive("jl_method_match_t") ||
Name.ends_with_insensitive("jl_vararg_t") ||
Name.ends_with_insensitive("jl_opaque_closure_t") ||
Name.ends_with_insensitive("jl_globalref_t") ||
// Probably not technically true for these, but let's allow it
Name.endswith_lower("typemap_intersection_env") ||
Name.endswith_lower("interpreter_state") ||
Name.endswith_lower("jl_typeenv_t") ||
Name.endswith_lower("jl_stenv_t") ||
Name.endswith_lower("jl_varbinding_t") ||
Name.endswith_lower("set_world") ||
Name.endswith_lower("jl_codectx_t")) {
Name.ends_with_insensitive("typemap_intersection_env") ||
Name.ends_with_insensitive("interpreter_state") ||
Name.ends_with_insensitive("jl_typeenv_t") ||
Name.ends_with_insensitive("jl_stenv_t") ||
Name.ends_with_insensitive("jl_varbinding_t") ||
Name.ends_with_insensitive("set_world") ||
Name.ends_with_insensitive("jl_codectx_t")) {
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct RemoveNIPass : PassInfoMixin<RemoveNIPass> {

struct MultiVersioningPass : PassInfoMixin<MultiVersioningPass> {
bool external_use;
MultiVersioningPass(bool external_use = false) : external_use(external_use) {}
MultiVersioningPass(bool external_use = false) JL_NOTSAFEPOINT : external_use(external_use) {}
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM) JL_NOTSAFEPOINT;
static bool isRequired() { return true; }
};
Expand Down
9 changes: 5 additions & 4 deletions src/pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,11 @@ namespace {
// }
}

#ifdef JL_DEBUG_BUILD
#ifdef JL_VERIFY_PASSES
static inline void addVerificationPasses(ModulePassManager &MPM, bool llvm_only) JL_NOTSAFEPOINT {
if (!llvm_only)
MPM.addPass(llvm::createModuleToFunctionPassAdaptor(GCInvariantVerifierPass()));
if (!llvm_only){
MPM.addPass(llvm::createModuleToFunctionPassAdaptor(GCInvariantVerifierPass(true)));
}
MPM.addPass(VerifierPass());
}
#endif
Expand Down Expand Up @@ -332,7 +333,7 @@ namespace {

static void buildEarlySimplificationPipeline(ModulePassManager &MPM, PassBuilder *PB, OptimizationLevel O, const OptimizationOptions &options) JL_NOTSAFEPOINT {
MPM.addPass(BeforeEarlySimplificationMarkerPass());
#ifdef JL_DEBUG_BUILD
#ifdef JL_VERIFY_PASSES
addVerificationPasses(MPM, options.llvm_only);
#endif
if (options.enable_early_simplifications) {
Expand Down

0 comments on commit c7bfbec

Please sign in to comment.