Commit graph

113 commits

Author SHA1 Message Date
Stéphan Kochen
d949180ab0 translate-c: create inline fn for always_inline 2021-10-20 17:58:30 -04:00
Andrew Kelley
1bbec59e07 clang API bindings: fix enum detection functions
These functions are intended to emit compile errors when Clang adds new
items to its enums. However, two of them were casting to the Zig enum
and switching on that, which wouldn't detect anything useful.
2021-10-01 11:39:12 -07:00
Andrew Kelley
3eb729b442 Merge remote-tracking branch 'origin/master' into llvm13 2021-09-30 21:38:04 -07:00
Josh Soref
664941bf14
Spelling corrections (#9833)
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2021-09-24 13:39:20 -04:00
Andrew Kelley
2f599b655b update src/ to LLVM 13 rc1 API 2021-08-16 01:11:10 -07:00
Evan Haas
bc18e93825 translate-c: better codegen for pointer index by int literal
#8589 introduced correct handling of signed (possibly negative) array access
of pointers. Since unadorned integer literals in C are signed, this resulted
in inefficient generated code when indexing a pointer by a non-negative
integer literal.
2021-08-03 08:38:15 +03:00
Evan Haas
c090e38340
translate-c: add support for ChooseExpr 2021-07-28 08:06:22 -07:00
Evan Haas
0e7897a9a2 translate-c: Remove usage of extern enum
Translate enum types as the underlying integer type. Translate enum constants
as top-level integer constants of the correct type (which does not necessarily
match the enum integer type).

If an enum constant's type cannot be translated for some reason, omit it.

See discussion https://github.com/ziglang/zig/issues/2115#issuecomment-827968279

Fixes #9153
2021-06-23 08:44:25 +03:00
Evan Haas
ea4a25287e translate-c: better support for static local variables
Don't move static local variables into the top-level scope since this
can cause name clashes if subsequently-defined variables or parameters
in different scopes share the name.

Instead, use a variable within a struct so that the variable's lexical
scope does not change. This solution was suggested by @LemonBoy

Note that a similar name-shadowing problem exists with `extern` variables
declared within block scope, but a different solution will be needed since
they do need to be moved to the top-level scope and we can't rename them.
2021-06-12 23:12:37 +03:00
Evan Haas
45212e3b33 translate-c: Implement flexible arrays
Fixes #8759
2021-06-11 21:31:39 +03:00
Evan Haas
a9dd8d7543 translate-c: Fix performance hazard in transPreprocessorEntities
Fixes O(N^2) behavior of `transPreprocessorEntities` due to repeated calls to
`mem.len`

Closes #8959
2021-06-02 09:12:45 +03:00
Evan Haas
1273bc277f translate-c: add support for __cleanup__ attribute
Use a `defer` statement to implement the C __cleanup__ attribute.

See https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
2021-05-19 12:12:18 +03:00
Evan Haas
36da8d02b5 translate-c: translate global (file scope) assembly 2021-05-15 11:53:01 +03:00
LemonBoy
7c3896e6cd translate-c: Prevent mistranslation of fp literals
When trying to retrieve 80bit fp values from clang using
getValueAsApproximateDouble we'd eventually hit the ceiling value and
return infinity, an invalid value for a fp literal.

Add some logic to prevent this error and warn the user.

Closes #8602
2021-04-24 18:42:23 +02:00
Michael Dusan
93cf9560b1
Merge remote-tracking branch 'origin/master' into llvm12 2021-04-11 17:40:19 -04:00
Evan Haas
8de14a98a6 translate-c: Add support for vector expressions
Includes vector types, __builtin_shufflevector, and __builtin_convertvector
2021-04-06 11:22:27 -07:00
Andrew Kelley
b85ef2300f Merge remote-tracking branch 'origin/master' into llvm12 2021-03-28 21:42:56 -07:00
Evan Haas
c558a1ae26 translate-c: Implement generic selection expressions
Enables translation of C code that uses the `_Generic` keyword
2021-03-17 00:07:33 +02:00
Andrew Kelley
1f34c03ac1 Merge remote-tracking branch 'origin/master' into llvm12 2021-03-12 18:05:27 -07:00
Evan Haas
c760532be0 translate-c: Add compound literal support 2021-03-08 10:09:12 +02:00
Andrew Kelley
584cb2e4fb Merge remote-tracking branch 'origin/master' into llvm12 2021-03-01 12:09:26 -07:00
Evan Haas
294ee1bbc9 translate-c: add limited OffsetOfExpr support
Add support for OffsetOfExpr that contain exactly 1 component, when that component
is a field.

For example, given:

```c
struct S {
  float f;
  double d;
};
struct T {
  long l;
  int i;
  struct S s[10];
};
```

Then:
```c
offsetof(struct T, i)       // supported
offsetof(struct T, s[2].d)  // not supported currently
```
2021-02-28 21:56:57 +02:00
Andrew Kelley
9e8943736e Merge remote-tracking branch 'origin/master' into llvm12 2021-02-27 02:25:58 -07:00
Evan Haas
0816981561 translate-c: add typeof support 2021-02-25 22:33:42 -08:00
Andrew Kelley
0b58b61799 Merge remote-tracking branch 'origin/master' into llvm12
Conflicts:
 * src/clang.zig
 * src/llvm.zig
   - this file got moved to src/llvm/bindings.zig in master branch so I
     had to put the new LLVM arch/os enum tags into it.
 * lib/std/target.zig, src/stage1/target.cpp
   - haiku had an inconsistency with its default target ABI, gnu vs
     eabi. In this commit we make it gnu in both places to match the
     latest changes by @hoanga.
 * src/translate_c.zig
2021-02-25 21:04:23 -07:00
Veikka Tuominen
9a826ccbe0
translate-c: elide some unecessary casts of literals 2021-02-16 16:40:43 +02:00
Evan Haas
221f1d898c translate-c: Improve function pointer handling
Omit address-of operator if operand is a function.

Improve handling of function-call translation when using function pointers

Fixes #4124
2021-02-08 10:15:00 +02:00
Evan Haas
57b2176e28 translate-c: Improve array support
1. For incomplete arrays with initializer list (`int x[] = {1};`) use the
initializer size as the array size.

2. For arrays initialized with a string literal translate it as an array
of character literals instead of `[*c]const u8`

3. Don't crash if an empty initializer is used for an incomplete array.

4. Add a test for multi-character character constants

Additionally lay some groundwork for supporting wide string literals.

fixes #4831 #7832 #7842
2021-01-25 10:37:23 -08:00
Jakub Konka
1c40a4df09 Update zig_llvm.cpp and other bits
Include updates to corresponding zig sources

llvm commit b2851aea80e5a8f0cfd6c3c5a56a6b00fb28c6b6
2020-12-16 18:13:58 +01:00
Andrew Kelley
e1ca6946be rename ZigClangFloatingLiteral_getValueAsApproximateDouble 2020-10-27 14:16:43 -07:00
Andrew Kelley
7067764ed3 Merge remote-tracking branch 'origin/master' into llvm11
The changes to install_files.h needed to put into src/libcxx.zig
2020-09-30 02:55:41 -07:00
Andrew Kelley
800a4a6ceb eliminate dependency of libzigcpp.a on libzigstage1.a
This allows us to create a build of self-hosted with LLVM extensions
enabled but without the stage1 backend.
2020-09-23 00:00:24 -07:00
Andrew Kelley
1de2c647df Merge remote-tracking branch 'origin/master' into llvm11 2020-08-18 15:32:42 -07:00
Vexu
cf5932b236
translate-c: convert int to bool if bool is expected 2020-08-11 12:24:45 +03:00
Andrew Kelley
c6e0df6213 Merge remote-tracking branch 'origin/master' into llvm11 2020-08-04 17:09:40 -07:00
Vexu
4ab2f947f9
translate-c: recognize other type trait expressions
Closes #5979
2020-08-04 00:48:29 +03:00
Andrew Kelley
c8ea8cf5df update LLVM C++ API wrappers from llvm 10 to 11 2020-07-24 16:49:57 -07:00
Andrew Kelley
656ba530d8
Merge remote-tracking branch 'origin/master' into llvm10 2020-03-13 15:17:53 -04:00
Vexu
cb4c488cbd
translate-c support struct field alignment 2020-03-10 15:57:57 +02:00
Vexu
692a974c3e
translate-c reject structs with VLAs 2020-03-08 12:11:37 +02:00
Michael Dusan
bc75c0de6c stage1: fix compile error on macOS Xcode 11.4 2020-03-07 12:16:56 -05:00
Andrew Kelley
a63a2fdf76
update zig_clang bindings to release/10.x 2020-01-29 23:50:24 -05:00
Andrew Kelley
a95dce15ae
Merge remote-tracking branch 'origin/master' into llvm10 2020-01-29 23:33:12 -05:00
Feix Weiglhofer
a4a9330648 translate-c: Don't make const parameters mutable. (#4273)
* translate-c: Remove arg-prefix from const parameters.
* translate-c: Add unittest for const parameters.
2020-01-24 15:32:32 -05:00
Andrew Kelley
72589dbffe
zig_clang builds with llvm 10 2020-01-23 17:22:13 -05:00
Andrew Kelley
32dafbdadc
zig_clang: update StmtClass to llvm 10 2020-01-23 16:52:40 -05:00
Andrew Kelley
3588f99719
zig_clang: update TypeClass enum 2020-01-23 14:35:12 -05:00
LemonBoy
a284be3f69 Fix unsafe cast in translate_c
Fixes #4250
2020-01-22 17:58:57 -05:00
Andrew Kelley
fbe6af81fd
Merge remote-tracking branch 'origin/master' into llvm10 2020-01-16 13:01:36 -05:00
LemonBoy
0267afa9c0 Fix garbled error messages from clang 2020-01-16 12:16:30 -05:00