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

TLD: invalid initializers for file scope variables #103

Closed
PHHargrove opened this issue Jul 1, 2014 · 5 comments
Closed

TLD: invalid initializers for file scope variables #103

PHHargrove opened this issue Jul 1, 2014 · 5 comments

Comments

@PHHargrove
Copy link
Contributor

The following error on bug544 indicates that the definition _upcr_pthreadinfo is missing, but that is just a symptom rather than the true problem:

[bugzilla/bug544_st04] FAILED: UPC-To-C Translation or Link error       (NEW)
cd /home/phargrov/upc-runtime/BUILD-gcc64/dbg_cupc2c/upc-tests/bugzilla
/home/phargrov/upc-runtime/BUILD-gcc64/dbg_cupc2c/upcc -Ww,-Wno-duplicate-decl-specifier -Ww,-Werror=pointer-arith -g  -network=smp -pthreads -nolink-cache -T 4 -o bug544_st04 bug544.upc
upcc: Error building pthread objects with thread-local data:
bug544_obj.c:15:57: error: use of undeclared identifier '_upcr_pthreadinfo'; did you mean 'upcri_pthreadinfo_t'?
int * UPCR_TLD_DEFINE(pfoo, 8, 8) = &((*(_cupc2c_tld0 *)UPCR_TLD_ADDR(foo))[2]);
                                                        ^
/home/phargrov/upc-runtime/upcr_threads.h:348:64: note: expanded from macro 'UPCR_TLD_ADDR'
#  define UPCR_TLD_ADDR(name) ((void *)&((struct upcri_tld_t *)upcri_mypthreadinfo())->name)
                                                               ^
/home/phargrov/upc-runtime/upcr_threads.h:289:33: note: expanded from macro 'upcri_mypthreadinfo'
  #define upcri_mypthreadinfo() _upcr_pthreadinfo
                                ^
/home/phargrov/upc-runtime/upcr_threads.h:280:3: note: 'upcri_pthreadinfo_t' declared here
} upcri_pthreadinfo_t;
  ^

The clang-upc2c translation of bug544 contains:

typedef int _cupc2c_tld0[100];
_cupc2c_tld0 UPCR_TLD_DEFINE(foo, 400, 4);
int * UPCR_TLD_DEFINE(pfoo, 8, 8) = &((*(_cupc2c_tld0 *)UPCR_TLD_ADDR(foo))[2]);
int * UPCR_TLD_DEFINE(pcrazy, 8, 8) = &((*(_cupc2c_tld0 *)UPCR_TLD_ADDR(foo))[(&((*(_cupc2c_tld0 *)UPCR_TLD_ADDR(foo))[40]) - &((*(_cupc2c_tld0 *)UPCR_TLD_ADDR(foo))[30]))]);

The problem lies in the initializers for pfoo and pcrazy, which are themselves thread-specific values (expressions containing addresses of TLD). This produces an error because UPCR_TLD_ADDR() appears in the initializer and accesses the thread-specific _upcr_pthreadinfo variable, which is instantiated by UPCR_BEGIN_FUNCTION().

Meanwhile the Berkeley translator produces an error message (or two) instead:

upcc: error during UPC-to-C translation (sgiupc stage): 
bug544.upc:7: Initializer expression for 'pfoo' not supported by BUPC
bug544.upc:8: Initializer expression for 'pcrazy' not supported by BUPC
bug544.upc:8: Initializer expression for 'pcrazy' not supported by BUPC
@PHHargrove
Copy link
Contributor Author

The bug7 test is an example of a thread-specific TLD initializer that Berkeley UPC can handle, but clang-upc2c currently gets wrong.

The source contains:

extern int quux;
int * pquux = &quux;
[....]
int quux;

For which the Berkeley UPC translator generates code with an initializer appropriate only to the initial pthread (though no initializer is actually required at all):

extern int quux;
int*  UPCR_TLD_DEFINE(pquux, 8, 8) = &quux;
int UPCR_TLD_DEFINE_TENTATIVE(quux, 4, 4);

PLUS the initialzier code which sets the right value for any thread:

void UPCRI_INIT_bug7_6953366925489(void) {
UPCR_BEGIN_FUNCTION();
UPCR_SET_SRCPOS("_bug7_6953366925489_INIT",0);
*((int* *) UPCR_TLD_ADDR(pquux)) = (int* )UPCR_TLD_ADDR(quux);
}

The translation from clang-upc2c attempts to perform the thread-specific initialization at file scope, and no initialization code:

int UPCR_TLD_DEFINE(quux, 4, 4);
int * UPCR_TLD_DEFINE(pquux, 8, 8) = &(*(int *)UPCR_TLD_ADDR(quux));
[...]
int UPCR_TLD_DEFINE(quux, 4, 4);

Also note that the "extern int quux" has been translated to a NON-tentative definition, which is probably not correct in general.

@PHHargrove
Copy link
Contributor Author

This appears to be resolved by 4a3b381.
Since this issue is a regression relative to master (created and resolved on the branch) I am closing it.

@PHHargrove
Copy link
Contributor Author

The dynamic initializers generated for pfoo and pcrazy in order to fix this issue are incorrect. So, I am reopenning this issue rather than creating a new one.

The current problem is that the TLD accessor macro does not appear on the LHS of the following:

    pfoo = &((*(_cupc2c_tld0 *)UPCR_TLD_ADDR(foo))[2]);
    pcrazy = &((*(_cupc2c_tld0 *)UPCR_TLD_ADDR(foo))[(&((*(_cupc2c_tld0 *)UPCR_TLD_ADDR(foo))[40]) - &((*(_cupc2c_tld0 *)UPCR_TLD_ADDR(foo))[30]))]);

The left-hand sides should also be expressions involving UPCR_TLD_ADDR().

@PHHargrove PHHargrove reopened this Jul 26, 2014
@PHHargrove PHHargrove changed the title TLD: invalid initializers at file scope TLD: invalid initializers for file scope variables Jul 26, 2014
@PHHargrove
Copy link
Contributor Author

A possible fix is now in testing.

@PHHargrove
Copy link
Contributor Author

Fixed in 59ca342

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

1 participant