Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is Trick ICG missing some uses of TRICK_ICG #608

Closed
alexlin0 opened this issue Apr 23, 2018 · 2 comments
Closed

Is Trick ICG missing some uses of TRICK_ICG #608

alexlin0 opened this issue Apr 23, 2018 · 2 comments
Assignees

Comments

@alexlin0
Copy link
Contributor

Test to see if Trick is catching the use of TRICK_ICG in this statement

#if !defined(SWIG) && !defined(TRICK_ICG)

We may be missing this case, and only on the Mac.

alexlin0 added a commit that referenced this issue Apr 23, 2018
Yes, it is, it's missing all of them.  Any clang/llvm version 3.5 and
above.  So it's been broken for a while.  We inherit from a
clang class that processes preprocessing statements.  If we override
virtual functions of a certain signature, we can inject our code into
the preprocessing process.  In this case we're looking for the use
of TRICK_ICG.  Clang changed the function signature in version 3.5.
From 3.5 on our functions were never called, so we never would find
TRICK_ICG.  I created new signatures for the functions post 3.5 so
they will work again.
alexlin0 added a commit that referenced this issue May 18, 2018
Some functions changed signatures in 3.5, others in 3.7.
@excaliburtb
Copy link
Contributor

Probably not getting the following syntax still:

#if  !defined(SWIG) && !defined(TRICK_ICG)
      CheckpointHelper_alias::UnsafeChkptVector<BODY_DATA *> workingBodies; /* ** list of bodies to be processed by parallel tasks */
#endif

@alexlin0 alexlin0 reopened this Oct 1, 2018
@dbankieris
Copy link
Contributor

dbankieris commented Apr 1, 2021

FindTrickICG::If is called whenever clang encounters a preprocessor IF directive, which seems to include at least #if, #ifdef, and #ifndef. If the directive includes TRICK_ICG, ICG marks all files in the current include chain as being tainted, meaning we must use offsetof in the init_attr functions to get address information for the ATTRIBUTES arrays. If multiple files include the same tainted file, only the files in the include chain when the tainted file is first encountered will be properly marked. This is because the header guard in the tainted file prevents clang from seeing TRICK_ICG in subsequent includes of that file. While this page says that the preprocessor still parses text within a failed conditional, the page on once-only headers reveals that the preprocessor not does rescan headers with guards if they've already been processed. In any case, FindTrickICG::If is not called for subsequent includes of a tainted header. More info on the multiple-include optimization.

In the example below, Bar.hh and Baz.hh both include the tainted Foo.hh. While io_Bar.cpp calls offsetof to correct the offsets in its ATTRIBUTES array, io_Baz.cpp does not, and its offsets remain wrong.

Foo.hh

// @trick_parse{everything}
#ifndef FOO_HH
#define FOO_HH

class Foo {
    #ifndef TRICK_ICG
    int i;
    int j;
    int k;
    #endif
};

#endif

Bar.hh

// @trick_parse{everything}
#include "Foo.hh"

class Bar {
    public:
    Foo foo;
    int i;
};

Baz.hh

// @trick_parse{everything}
#include "Foo.hh"

class Baz {
    public:
    Foo foo;
    int i;
};

io_Bar.cpp

void init_attrBar() {

    static int initialized ;
    if (initialized) {
        return;
    }   
    initialized = 1;

    attrBar[0].offset = offsetof(Bar, foo) ;
    trick_MM->add_attr_info(std::string(attrBar[0].type_name) , &attrBar[0], __FILE__ , __LINE__ ) ; 
    attrBar[1].offset = offsetof(Bar, i) ;
}

io_Baz.pp

void init_attrBaz() {

    static int initialized ;
    if (initialized) {
        return;
    }   
    initialized = 1;

    trick_MM->add_attr_info(std::string(attrBaz[0].type_name) , &attrBaz[0], __FILE__ , __LINE__ ) ;
}

I haven't found anything about disabling multiple-include optimization (which would impact build speed anyway), so we'll probably have to add some more smarts to ICG.

spfennell pushed a commit that referenced this issue Apr 6, 2021
…d include chains for headers that have already been preprocessed
spfennell pushed a commit that referenced this issue Apr 6, 2021
spfennell pushed a commit that referenced this issue Apr 6, 2021
spfennell added a commit that referenced this issue Apr 20, 2021
* #608 add implementation of FileSkipped callback to FindTrickICG to add include chains for headers that have already been preprocessed

* #608 add test SIM for FindTrickICG offsets SIM_test_icg_file_skipped
@spfennell spfennell self-assigned this Apr 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants