String literals must be in constant address space.
Details
Diff Detail
Event Timeline
lib/Sema/SemaExpr.cpp | ||
---|---|---|
3053 | Will it work if we fix this issue inside StringLiteral::Create method? |
lib/Sema/SemaExpr.cpp | ||
---|---|---|
3051 | Do we still need this? |
lib/Sema/SemaExpr.cpp | ||
---|---|---|
3053 | I have added the address space to the creation of StringLiteral, but unfortunately it doesn't seems like we can remove similar code in other places because QualType created for StringLiteral is also used elsewhere and has to match (contain right address space). I.e. here is it used further down to create PredefinedExpr. So not sure there is any value in doing the change in StringLiteral construction really. Unless we could keep it and use getType() from StringLiteral to resent the QualType to be used further down. Let me know what you think about it? |
lib/AST/Expr.cpp | ||
---|---|---|
870 | As Ty is passed by value, shouldn't we accept only data located in constant address space? | |
lib/Sema/SemaExpr.cpp | ||
3051 | String type can only be a constant arrays. |
lib/AST/Expr.cpp | ||
---|---|---|
870 | Do you mean to assert? Currently it should be passed with constant AS but I thought the idea is to modify this function so we can accept Default AS too but then replace by constant. | |
lib/Sema/SemaExpr.cpp | ||
3051 | Yes, I think we need to be able to declare const arrays in different ASes. I.e. this is valid code in OpenCL: __private const int* a = ...; Quick check for getConstantArrayType, it seems to be used in many different place. So I don't think I can just modify it. |
lib/AST/Expr.cpp | ||
---|---|---|
870 | Yes, but according to your other comment this idea doesn't work.
|
lib/AST/Expr.cpp | ||
---|---|---|
870 | Indeed for the current cases it doesn't... there might be some uncaught ones though where it can be useful. But we can add it later as well. So I am thinking to undo this? |
lib/AST/Expr.cpp | ||
---|---|---|
870 | I quite liked the idea initially, but unfortunately it seems like it's not applicable to the current use cases. |
Can you add a codegen test for 1.2, 2.0?
Also, I am wondering whether this is valid for OpenCL C++. Do we need special handling for string literal?
lib/AST/Expr.cpp | ||
---|---|---|
870 | Can you extract this as QualType ASTContext::getStringLiteralType(QualType); then use it here and below? | |
test/SemaOpenCL/predefined-expr.cl | ||
1 | can you also check for cl 2.0? |
The best way of adding common helper function I could come up with. The problem is that string literals are created quite differently all over: using various char types and const qualifiers. That seems to cover the most common case now.
Anything specific you would like me to check? I am not modifying anything in CodeGen here though.
Also, I am wondering whether this is valid for OpenCL C++. Do we need special handling for string literal?
Actually OpenCL C++ makes no statement about string literal. But I think we will want it to be in constant AS. I will raise it with Khronos.
You changed the AST of string literal. We need to check whether the CodeGen for string literal still works.
lib/AST/ASTContext.cpp | ||
---|---|---|
3632 | This is not right. The base type of a string literal may not be CharTy, therefore this function needs an input argument which is the original base type and it returns the adjusted base type. (Maybe it should be renamed as adjustStringLiteralBaseType?) Also, you can then use it in StringLiteral::CreateEmpty by passing an empty QualType(). |
- Changed to adjust common function
- Enhanced CodeGen string literal case to also check the predefined expr
This is not right. The base type of a string literal may not be CharTy, therefore this function needs an input argument which is the original base type and it returns the adjusted base type. (Maybe it should be renamed as adjustStringLiteralBaseType?) Also, you can then use it in StringLiteral::CreateEmpty by passing an empty QualType().