This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/TM4C129CNCZAD: C++ calls that return a pointer cause an unaligned access fault

Part Number: TM4C129CNCZAD

Tool/software: TI C/C++ Compiler

class Board {
 public:
  virtual ~Board();
  Syslog* syslog() { return syslog_; };
 protected:
  Board()
      : syslog_(NULL) {};

  Syslog* syslog_;
}

class BoardImpl : public Board {
 public:
  BoardImpl();
};

BoardImpl::BoardImpl() : Board() {
  Board::syslog_ = Syslog::Init();
}

void some_function() {
  BoardImpl board;
  Board *board_ptr = &board;
  Syslog* syslog_local = board_ptr->syslog();

  // works fine
  syslog_local->Printf("blah");

  // crashes with unaligned access
  board_ptr->syslog()->Printf("blah");

}

Can someone tell me why the above code crashes?  We're using compiler 15.12.5, and we consistently see this crash happen on a TM4C if we use a function call that returns a pointer, then dereference it in this way.  I suspect the compiler's not doing the right thing.

  • If it is easy, please build this code to run on a hosted system, like a laptop.  If you can do that, does it work there?

    To understand what happened, I need a test case which allows me to reproduce it.  The directions in the article How to Submit a Compiler Test Case show how to create a test case that builds, but usually is not enough to execute.  In this particular case, I think you only need to rename some_function to main, and it will be a complete standalone program.  If it is easy as that, I'd appreciate if you could make this test case one that runs.  At any rate, I'd appreciate whatever test case you can submit.

    Thanks and regards,

    -George

  • Hi George,

    `board_ptr->syslog()->Printf("blah");` works fine in our linux systems with gcc or clang as the compiler, it's only on the TI chip with the TI compiler that I see this issue.  Can you attempt to reproduce it from the code I already posted?  Our compiler options are listed below:

    -mv7M4
    --code_state=16
    --float_support=FPv4SPD16
    -me
    -Ooff
    --check_misra="all,-2.2,-6.2,-8.1,-10.1,-10.3,-10.5,-12.2,-12.6,-12.8,-12.9,-17.4,-17.6,-19.1,-19.4,-19.7,-19.13,-20.9,-20.10"
    -g
    --gcc --define=TIVAWARE
    --define=TARGET_IS_TM4C129_RA0
    --define=PART_TM4C129CNCZAD
    --display_error_number
    --emit_warnings_as_errors
    --diag_warning=225
    --diag_wrap=off
    --gen_func_subsections=on
    --unaligned_access=off
    --abi=eabi
    --ual 

  • Kaveh Vaghefi said:
    We're using compiler 15.2.5

    I don't think version 15.2.5 exists. Do you mean 5.2.5 or 15.12.5?

    Kaveh Vaghefi said:
    Can you attempt to reproduce it from the code I already posted?

    I attempted to repeat the failure using TI ARM compiler v5.2.6 or v15.12.5, but failed to reproduce the failure. The posted code seems incomplete:

    1) The is no code for the Syslog class, so had to guess the content. Based upon the following line think Syslog::Init is a static member function:

      Board::syslog_ = Syslog::Init();

    2) There is a syntax error in that no terminating semicolon for the Board class.

    3) The following line didn't compile:

      Board board_ptr = &board;

    Looks like the board_ptr variable should be declared as a pointer to class Board:

      Board *board_ptr = &board;

    Can you post a complete compilable code example which demonstrates the problem? 

  • My apologies, yes there are a couple typos, I'll fix them up, and the compiler version is 15.12.5.  I have to remove a bunch of items in order to post a simple case of what we're doing here on the forums (I can't just copy and paste the code we use).  Is there a more private way to share code?

  • Kaveh Vaghefi said:
    Is there a more private way to share code?

    Yes. Please see the sub-section titled Protecting Intellectual Property in the article How to Submit a Compiler Test Case.

    Thanks and regards,

    -George