AdeptLanguage / Adept

The Adept Programming Language
GNU General Public License v3.0
119 stars 9 forks source link

Adept compiler crashed with this code #201

Closed ghost closed 11 months ago

ghost commented 11 months ago

I'm translating jvmticmlr.h to Adept.

/*
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Oracle designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

/*
 * This header file defines the data structures sent by the VM
 * through the JVMTI CompiledMethodLoad callback function via the
 * "void * compile_info" parameter. The memory pointed to by the
 * compile_info parameter may not be referenced after returning from
 * the CompiledMethodLoad callback. These are VM implementation
 * specific data structures that may evolve in future releases. A
 * JVMTI agent should interpret a non-NULL compile_info as a pointer
 * to a region of memory containing a list of records. In a typical
 * usage scenario, a JVMTI agent would cast each record to a
 * jvmtiCompiledMethodLoadRecordHeader, a struct that represents
 * arbitrary information. This struct contains a kind field to indicate
 * the kind of information being passed, and a pointer to the next
 * record. If the kind field indicates inlining information, then the
 * agent would cast the record to a jvmtiCompiledMethodLoadInlineRecord.
 * This record contains an array of PCStackInfo structs, which indicate
 * for every pc address what are the methods on the invocation stack.
 * The "methods" and "bcis" fields in each PCStackInfo struct specify a
 * 1-1 mapping between these inlined methods and their bytecode indices.
 * This can be used to derive the proper source lines of the inlined
 * methods.
 */

// anonymous enums are currently not allowed

//foreign enum (
    define JVMTI_CMLR_MAJOR_VERSION_1 = 0x00000001//,
    define JVMTI_CMLR_MINOR_VERSION_0 = 0x00000000//,

    define JVMTI_CMLR_MAJOR_VERSION   = 0x00000001//,
    define JVMTI_CMLR_MINOR_VERSION   = 0x00000000

    /*
     * This comment is for the "JDK import from HotSpot" sanity check:
     * version: 1.0.0
     */
//)

alias jint = int // temporary hack

// assigning values to enums currently not allowed

foreign enum jvmtiCMLRKind (
    JVMTI_CMLR_DUMMY       ,//= 1,
    JVMTI_CMLR_INLINE_INFO //= 2
)

/*
 * Record that represents arbitrary information passed through JVMTI
 * CompiledMethodLoadEvent void pointer.
 */
struct _jvmtiCompiledMethodLoadRecordHeader (
  kind jvmtiCMLRKind,     /* id for the kind of info passed in the record */
  majorinfoversion jint,  /* major and minor info version values. Init'ed */
  minorinfoversion jint,  /* to current version value in jvmtiExport.cpp. */

  next *_jvmtiCompiledMethodLoadRecordHeader
)

alias jvmtiCompiledMethodLoadRecordHeader = _jvmtiCompiledMethodLoadRecordHeader

/*
 * Record that gives information about the methods on the compile-time
 * stack at a specific pc address of a compiled method. Each element in
 * the methods array maps to same element in the bcis array.
 */
struct _PCStackInfo (
  pc ptr,             /* the pc address for this compiled method */
  numstackframes jint,  /* number of methods on the stack */
  methods *jmethodID,   /* array of numstackframes method ids */
  bcis *jint,           /* array of numstackframes bytecode indices */
)

alias PCStackInfo = _PCStackInfo

/*
 * Record that contains inlining information for each pc address of
 * an nmethod.
 */
struct _jvmtiCompiledMethodLoadInlineRecord (
  header jvmtiCompiledMethodLoadRecordHeader,  /* common header for casting */
  numpcs jint,          /* number of pc descriptors in this nmethod */
  pcinfo *PCStackInfo  /* array of numpcs pc descriptors */
)

alias jvmtiCompiledMethodLoadInlineRecord = _jvmtiCompiledMethodLoadInlineRecord

/*
 * Dummy record used to test that we can pass records with different
 * information through the void pointer provided that they can be cast
 * to a jvmtiCompiledMethodLoadRecordHeader.
 */

struct _jvmtiCompiledMethodLoadDummyRecord (
  header jvmtiCompiledMethodLoadRecordHeader,  /* common header for casting */
  message [50] ubyte
)

alias jvmtiCompiledMethodLoadDummyRecord = _jvmtiCompiledMethodLoadDummyRecord
ghost commented 11 months ago
adept.exe caused an Access Violation at location 00007FF85A8E2D30 in module ucrtbase.DLL Reading from location FFFFFFFFFFFFFFFF.

AddrPC           Params
00007FF85A8E2D30 00007FF710D9E2BF 00007FF70E1ED4E5 00000025E564F790  ucrtbase.DLL!strlen+0x10
00007FF70E175035 00000025E5850000 00007FF710D9E0E5 0000000000000000  adept.exe!llvm_create_global_string+0x15
00007FF70E175AA4 0000000000000040 00000025E70B50A0 00000025E70D8678  adept.exe!build_llvm_check_on_failure_block+0xc4
00007FF70E178CE7 0000000000000047 00007FF800000002 00000025E70BD360  adept.exe!ir_to_llvm_basicblocks+0x157
00007FF70E179A02 00000025E578AF60 00000025E564FA20 00000025E588E460  adept.exe!ir_to_llvm_inject_deinit_built+0x1c2
00007FF70E174520 00000025E564FA20 00000025E587FFB0 00000025E5867140  adept.exe!ir_to_llvm+0x550
00007FF70E17F64C 00000025E587A6F0 0000000000000101 0000000000000000  adept.exe!compiler_invoke+0x3fc
00007FF70E17F73D 00007FF710D319A0 00007FF712096F50 0000000000000000  adept.exe!compiler_run+0xd
00007FF710C4B799 00007FF712F21050 00007FF712F21058 0000000000000000  adept.exe!main+0x39
00007FF70E1612EF 0000000000000000 0000000000000000 0000000000000000  adept.exe!__tmainCRTStartup+0x16f
00007FF70E161406 0000000000000000 0000000000000000 0000000000000000  adept.exe!mainCRTStartup+0x16
00007FF865EA13D2 00007FF865EA13B0 0000000000000000 0000000000000000  KERNEL32.DLL!BaseThreadInitThunk+0x22
00007FF8682903C4 0000000000000000 0000000000000000 0000000000000000  ntdll.dll!RtlUserThreadStart+0x34
IsaacShelton commented 11 months ago

That's weird I'll look into it

IsaacShelton commented 11 months ago

This crash occurred because there was no main-like function. This bug has been fixed in the latest nightly.